I’m having trouble getting a sample program to link correctly (in this case against the ICU library). When I do ‘make’, everything builds fine. But when I run it, it says it can’t find one of the .so’s. I double checked they’re all installed in /usr/local/lib. What I discovered was it was looking in /usr/lib. If I symlink from there to there actual location, it works.
Why is my LIBPATHS being ignored or not used?
Here is the Makefile
CC = g++
INCPATHS = -I/usr/local/include
CFLAGS = -c -Wall $(INCPATHS)
LIBPATHS = -L/usr/local/lib/
LIBS = $(LIBPATHS) -licuio -licui18n -licuuc -licuio -licudata
EXECUTABLE = prog
print_linking = echo -e "\033[32m" "Linking: $<" "\033[39m"
print_compiling = echo -e "\033[33m" "Compiling: $<" "\033[39m"
print_cleaning = echo -e "\033[31m" "Cleaning: `pwd`" "\033[39m"
all: main
# [target]: [dependencies]
# <tab> system command
main: main.o
@$(print_linking)
@$(CC) -o $(EXECUTABLE) main.o $(LIBS) >> /dev/null
main.o: main.cpp
@$(print_compiling)
@$(CC) $(CFLAGS) main.cpp
clean:
@$(print_cleaning)
@rm -rf *.o *~ $(EXECUTABLE)
Your
LIBPATHStells the linker where to find the library when linking to resolve symbols.At runtime, you need to tell the loader where to find the library. It doesn’t know about what happened at compile time. You can use the
LD_LIBRARY_PATHvariable as mentioned above, or check into/etc/ld.so.confand it’s friends.