我尝试了-L命令直接更改链接器搜索,甚至尝试了-Wl,-rpath,/ mydir和-Wl,-rpath-link,/ mydir,但是g ++似乎仍在搜索/ usr / bin / ld。我在这里做错了什么?抱歉,如果我在没有IDE的情况下刚接触新东西,那是公然的错误。
我当前正在使用的Makefile。
#Makefile for compiling library.
CC = g++
CURNTDIR = $(shell pwd)
IFLAG = -I$(CURNTDIR)/include
LFLAG = -L$(CURNTDIR)/lib
LIBS = -llibSDLmain -llibSDL2
CXXFLAGS = -Wl,-rpath,$(CURNTDIR)/lib -Wl,-rpath-link,$(CURNTDIR)/lib
objs = SpiceMain.o SystemHandler.o
SpiceMain: $(objs)
$(CC) -o $@ $(CXXFLAGS) $(IFLAG) $(LFLAG) $(objs) $(LIBS)
SpiceMain.o: SpiceMain.cpp
$(CC) -c $(CXXFLAGS) $(IFLAG) $(LFLAG) $? $(LIBS)
SystemHandler.o: SystemHandler.cpp
$(CC) -c $(CXXFLAGS) $(IFLAG) $(LFLAG) $? $(LIBS)
clean:
rm $(objs)
rm SpiceMain
返回的终端错误。
g++ -o SpiceMain -Wl,-rpath,/home/harry/Desktop/programs/spiceengine/lib -Wl,-rpath-link,/home/harry/Desktop/programs/spiceengine/lib -I/home/harry/Desktop/programs/spiceengine/include -L/home/harry/Desktop/programs/spiceengine/lib SpiceMain.o SystemHandler.o -llibSDLmain -llibSDL2
/usr/bin/ld: cannot find -llibSDLmain
/usr/bin/ld: cannot find -llibSDL2
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: SpiceMain] Error 1
在此先感谢任何可以提供帮助的人。
答案 0 :(得分:2)
我认为您需要省略“ lib *”前缀(和* .so后缀):
-L/my/library/path -lSDLmain -lSDL2