Makefile链接共享(动态)库
问题描述:
我有一个连接共享(动态)库.so或.dylib从我的一个项目与另一个项目的问题。Makefile链接共享(动态)库
我使用这样的Makefile:
#libraries
#custom
COMPARERS_STATIC_LIB_PATH=../comparers/output/debug/lib/libcomparers.a
COMPARERS_LIB_DIR=../comparers/output/debug/lib/
$(SHARED_LIBRARY): assertion.o
$(CC) $(CFLAGS) -L$(COMPARERS_LIB_DIR) -shared -o $(OUTPUTS_LIB_DIR)/$(SHARED_LIBRARY) $(OUTPUTS_DIR)/assertion.o -lcomparers
$(DYNAMIC_LIBRARY): assertion.o
$(CC) $(CFLAGS) -L$(COMPARERS_LIB_DIR) -dynamiclib -o $(OUTPUTS_LIB_DIR)/$(DYNAMIC_LIBRARY) $(OUTPUTS_DIR)/assertion.o -lcomparers
的目录和库到位作为下面的图片。
与静态库编译和链接链接正确:
$(TARGET): $(LIBRARY)
$(CC) $(CFLAGS) -o $(OUTPUTS_BIN_DIR)/$(TARGET) src/main.c $(OUTPUTS_LIB_DIR)/$(LIBRARY) $(COMPARERS_STATIC_LIB_PATH)
的错误,我得到:
gcc -g -Wall -D__USE_FIXED_PROTOTYPES__ -std=c99 -I./include -I../comparers/include -L../comparers/output/debug/lib/ -shared -o outputs/debug/lib/libunit_tests.so outputs/debug/assertion.o -lcomparers
ld: warning: directory not found for option '-L../comparers/output/debug/lib/'
ld: library not found for -lcomparers
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libunit_tests.so] Error 1
答
你有一个错字,你$(COMPARERS_LIB_DIR)
包含:
../comparers/output/debug/lib/
但必须是:
../comparers/outputs/debug/lib/
^
涉及到你的身材。
是的,愚蠢的错误。谢谢。 –