Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ -L和-L命令不';不能在Makefile中工作_C++_C_Gcc_Makefile - Fatal编程技术网

C++ -L和-L命令不';不能在Makefile中工作

C++ -L和-L命令不';不能在Makefile中工作,c++,c,gcc,makefile,C++,C,Gcc,Makefile,我有以下Makefile: TOP = ../Bank/src CC = gcc CFLAGS = -g -Wall -std=c99 LDFLAGS = -L$(TOP) LFLAGS = -lVirtualBank INCLUDES = -I$(TOP)/VirtualBank/ LIBS = VirtualBank.a BANK_SOURCES = $(TOP)/bank.c VirtualBank_SOURCES = $(TOP)/VirtualBank/bankServer.

我有以下Makefile:

TOP = ../Bank/src
CC = gcc

CFLAGS = -g -Wall -std=c99
LDFLAGS = -L$(TOP)
LFLAGS = -lVirtualBank
INCLUDES = -I$(TOP)/VirtualBank/ 
LIBS = VirtualBank.a
 
BANK_SOURCES = $(TOP)/bank.c 
VirtualBank_SOURCES = $(TOP)/VirtualBank/bankServer.c $(TOP)/VirtualBank/dataBase.c $(TOP)/VirtualBank/account.c
 
BANK_OBJECTS = $(BANK_SOURCES:.c=.o)
VirtualBank_OBJECTS = $(VirtualBank_SOURCES:.c=.o)
TARGET = bank

all: VirtualBank.a $(TARGET)
    
VirtualBank.a:$(VirtualBank_OBJECTS)
    rm -f $@
    ar cq $@ $(VirtualBank_OBJECTS)
    mv *.a $(TOP)/

$(VirtualBank_OBJECTS):$(VirtualBank_SOURCES)
    $(CC) -c $(CFLAGS) $(INCLUDES) $(VirtualBank_SOURCES)
    mv *.o $(TOP)/VirtualBank/

$(TARGET):$(BANK_OBJECTS) 
    $(CC) $(CFLAGS) $(INCLUDES) $(BANK_OBJECTS) -o $(TARGET) $(LDFLAGS) $(LFLAGS)
    chmod +x $(TARGET)
       
$(BANK_OBJECTS):$(BANK_SOURCES)
    $(CC) $(CFLAGS) -c $(INCLUDES) $(BANK_SOURCES)
    mv *.o $(TOP)/

       
clean: 
    cd ../Bank
    rm -rf *.o bank
    cd $(TOP)
    rm -rf *.o *.a
    cd $(TOP)/VirtualBank
    rm -rf *.o
它来自这个项目: 当我运行
make
命令时,commpiler找不到VirtualBank库。我认为问题出在-l命令上,我再次阅读了有关该命令的内容,但我没有找到问题所在

你能帮我吗

谢谢

编辑 错误消息:

gcc -g -Wall -std=c99 -I../Bank/src/VirtualBank/  ../Bank/src/bank.o -o bank -L../Bank/src -lVirtualBank
/usr/bin/ld: cannot find -lVirtualBank
collect2: error: ld returned 1 exit status
make: *** [bank] Error 1
发件人:

您的库名为VirtualBank.a,但ld将从以下位置查找libVirtualBank.a


您的库名为VirtualBank.a,但ld将查找libVirtualBank.a

您有VirtualBank库吗?何处?错误消息前的命令行是什么?它是在运行makefile时创建的。添加了错误之前的最后一个命令。这个命令:-L$(顶部)告诉编译器在这里查找lib,对吗?和-lVirtualBank使用它,对吗?您可以在
gcc
命令行中看到
-L../Bank/src
就在那里。这就是
LDFLAGS
扩展到的内容。我得出的结论是,
。/Bank/src
中没有
libVirtualBank.a
(或.so)。看起来这是因为你把它命名为
VirtualBank.a
。我建议使用名称
libVirtualBank.a
。您有VirtualBank库吗?何处?错误消息前的命令行是什么?它是在运行makefile时创建的。添加了错误之前的最后一个命令。这个命令:-L$(顶部)告诉编译器在这里查找lib,对吗?和-lVirtualBank使用它,对吗?您可以在
gcc
命令行中看到
-L../Bank/src
就在那里。这就是
LDFLAGS
扩展到的内容。我得出的结论是,
。/Bank/src
中没有
libVirtualBank.a
(或.so)。看起来这是因为你把它命名为
VirtualBank.a
。我建议使用libVirtualBank.a的名称。
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a ".so" extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

You may list the same archive multiple times on the command line.

This type of archive searching is standard for Unix linkers. However, if you are using ld on AIX , note that it is different from the behaviour of the AIX linker.