g++: how to specify preference of library path?
- by Heinrich Schmetterling
I'm compiling a c++ program using g++ and ld. I have a .so library I want to be used during linking. However, a library of the same name exists in /usr/local/lib, and ld is choosing that library over the one I'm directly specifying. How can I fix this?
For the examples below, my library file is /my/dir/libfoo.so.0. Things I've tried that don't work:
my g++ command is "g++ -g -Wall -o my_binary -L/my/dir -lfoo bar.cpp"
adding /my/dir to the beginning or end of my $PATH env variable
adding /my/dir/libfoo.so.0 as an argument to g++
Thanks.