如何链接makefile中的另一个库

时间:2013-11-24 23:53:17

标签: dll build makefile shared-libraries

我的makefile(不是我写的)如下

        SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
DEPENDS = $(SOURCES:.cpp=.d)
LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2 lua5.1) -llua5.1
CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2 lua5.1)
CXXFLAGS = $(CPPFLAGS) -W -Wall -g
CXX = g++
MAIN = game

all: $(MAIN)

depend: $(DEPENDS)

clean:
    rm -f *.o *.d $(MAIN)

$(MAIN): $(OBJECTS)
    @echo Creating $@...
    @$(CXX) -o $@ $(OBJECTS) $(LDFLAGS) 

%.o: %.cpp
    @echo Compiling $<...
    @$(CXX) -o $@ -c $(CXXFLAGS) $<

%.d: %.cpp
    @echo Building $@...
    @set -e; $(CC) -M $(CPPFLAGS) $< \
                  | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
                [ -s $@ ] || rm -f $@

include $(DEPENDS)

现在我想链接当前目录中的libfmodex.so,我尝试将它放在代码中的某个地方用-L。 libfmodex.so,但gcc说g ++:错误:libfmodex.so:没有这样的文件或目录,但我知道它在当前目录中,我究竟如何链接它?

1 个答案:

答案 0 :(得分:0)

添加LDFLAGS变量,例如:-L. -lfmodex