I am trying to link to an external library (the boost regex library) under gcc. I am ashamed to admit that what I know about linking external libraries comes soley from modified snipets from online forums. My problem is as follows; I use to keep all my source code in a single directory and build my executable with a simple makefile. Recently I separated a number of general utility programs and my projects into different directories. For each project I now have a master makefile which calls a secondary makefile responsible for my utility programs. That all seems to work fine, but my problem arises when I need link an external library. The linking process works fine when all source files reside in the same directory, but I can't get it to work otherwise. Here is a simplified example:
# master makefile resides in the project dir TRGTS = utilities project # path to utilities dir UTILS = ~/utilities all: $(TRGTS) utilities: cd $(UTILS) ; make #This is where I seem to be going wrong. project: proj.o $(UTILS)/utility.o g++ -ggdb -std=c++98 -I/usr/include/ proj.o -L /usr/lib -lboost_regex $(UTILS)/utility.o -o project proj.o: proj.cpp g++ -ggdb -c proj.cpp clean: rm proj.o project
and here is the makefile on which the target "utilities" (above) is dependant on:
#make file for utility programs all: utility.o utility.o: utility.cpp g++ -ggdb -c utility.cpp clean: rm utility.o
So just to recap a similar layout seems will work fine where linking to an external library is NOT required, but otherwise will fail with the warning that a number of .so files needed by /usr/lib/libboost_regex.so cannot be found. If anyone has any idea where I'm going wrong I'd be most grateful for your thoughts. My knowlege of linking is limited so if possible I'd also appreciate a breakdown of the process, i.e. what does the compiler need to know in order to link a library.
hope you can help!