Reputation: 11752
I have a problem with linking shared (dynamic) libraries .so or .dylib from my one project with another project.
I am using such 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
The directories and libraries are in place as on the below picture.
Linking with static library compiles and links correctly:
$(TARGET): $(LIBRARY)
$(CC) $(CFLAGS) -o $(OUTPUTS_BIN_DIR)/$(TARGET) src/main.c $(OUTPUTS_LIB_DIR)/$(LIBRARY) $(COMPARERS_STATIC_LIB_PATH)
The error I get:
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
Upvotes: 0
Views: 1556
Reputation: 5631
You have a typo, your $(COMPARERS_LIB_DIR)
contains:
../comparers/output/debug/lib/
but must be:
../comparers/outputs/debug/lib/
^
concerning to your figure.
Upvotes: 1