Convincing gcc to ignore system libraries in favour of locally installed libraries

Viewed 4330

I am trying to build a simple executable that uses boost_serialization and boost_iostreams.

#include <fstream>
#include <iostream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>

int main()
{
    using namespace boost::iostreams;
    filtering_ostream os;
    os.push(boost::iostreams::gzip_compressor());
    os.push(boost::iostreams::file_sink("emptyGzipBug.txt.gz"));
}

Unfortunately the system I am working with has a very outdated version of boost_serialization in /usr/lib/, and I have no way to change that.

I am fairly certain when I build the example using

g++ -o main main.cpp -lboost_serialization -lboost_iostreams

that the linker errors result because gcc uses the system version of boost_serialization rather than my locally installed version. Setting LIBRARY_PATH and LD_LIBRARY_PATH to /home/andrew/install/lib doesnt work. When i build using

g++ -o main main.cpp -L/home/andrew/install/lib -lboost_serialization -lboost_iostreams

then everything works.

My questions are:

  1. How can I get gcc to tell me the filenames of the libraries its using?

  2. Is it possible to setup the environment so that I dont have to specify the absolute path to my local boost on the command line of gcc.

2 Answers

-nodefaultlibs

       Do not use the standard system libraries when linking.  Only the
       libraries you specify are passed to the linker, and options
       specifying linkage of the system libraries, such as
       -static-libgcc or -shared-libgcc, are ignored.  The standard
       startup files are used normally, unless -nostartfiles is used.

       The compiler may generate calls to "memcmp", "memset", "memcpy"
       and "memmove".  These entries are usually resolved by entries in
       libc.  These entry points should be supplied through some other
       mechanism when this option is specified.

Haven't used it myself but it sounds exactly like what was asked for.

Related