Hi all,
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!

So it does not say that it cannot find libboost_regex.so?
In that case: does /usr/lib contain any other boost libraries?

If I remember right.. (I've used this library a while ago) the regex lib depends on some other boost libraries that you need to link to aswell. Maybe post the errors your getting for a better understanding of the problem.

Thanks for the response
I have posted the errors below.
/usr/lib does indeed contain a number of other boost libraries, though I have linked to boost regex before with the set of commands shown in the original post (code lines 12. and 13.), the only difference seems to be that now I have split my source code into a number of different directories.

Anyway here is the spiel from the command line starting from where we start to run into problems:

g++ -ggdb -std=c++98 -I/usr/include/ rmvStrNeighbs.o -L /usr/lib -lboost_regex /home/network/findlay/jfcpplib/Utilities/rdlines.o -o rmvStrNeighbs
/usr/bin/ld: warning: libicui18n.so.36, needed by /usr/lib/libboost_regex.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.36, needed by /usr/lib/libboost_regex.so, not found (try using -rpath or -rpath-link)
rmvStrNeighbs.o: In function `main':
/home/network/findlay/quasar_selection/data/pp_algs/halos_dnuts/rmvStrNeighbs.cpp:12: undefined reference to `rdlines::rtn_lines()'
/usr/lib/libboost_regex.so: undefined reference to `icu_3_6::Locale::Locale()'
/usr/lib/libboost_regex.so: undefined reference to `icu_3_6::Collator::createInstance(icu_3_6::Locale const&, UErrorCode&)'
/usr/lib/libboost_regex.so: undefined reference to `u_isblank_3_6'
/usr/lib/libboost_regex.so: undefined reference to `u_digit_3_6'
/usr/lib/libboost_regex.so: undefined reference to `u_charFromName_3_6'
/usr/lib/libboost_regex.so: undefined reference to `u_charType_3_6'
/usr/lib/libboost_regex.so: undefined reference to `icu_3_6::Locale::~Locale()'
/usr/lib/libboost_regex.so: undefined reference to `u_tolower_3_6'
/usr/lib/libboost_regex.so: undefined reference to `icu_3_6::Locale::Locale(icu_3_6::Locale const&)'
/usr/lib/libboost_regex.so: undefined reference to `u_isspace_3_6'
collect2: ld returned 1 exit status
make: *** [rmvStrNeighbs] Error 1

Since the same set of commands work where all source code is kept together and not when the source code is kept apart I tend to think that the compiler just isnt looking in the correct place for libicuuc.so.36 and libicuuc.so.36. What do you think?

Problem was with obscure libraries missing from my installation. Solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.