Results 1 to 5 of 5

Thread: C++/Boost linker errors

  1. #1
    Join Date
    May 2008
    Location
    UK
    Beans
    15
    Distro
    Kubuntu 14.04 Trusty Tahr

    C++/Boost linker errors

    Hi all,

    I've got this really simple C++ program that's using the Boost.Filesystem library:
    Code:
    #include <iostream>
    #include <boost/filesystem.hpp>
    
    int main()
    {
        boost::filesystem::path pathname = "/usr/local/bin";
        std::cout << pathname.string() << std::endl;
        return 0;
    }
    It compiles fine, and I can get it to link to the shared object:
    g++ -I/usr/local/include/boost-1_35 -o test test.cpp -lboost_filesystem-gcc42-mt-1_35
    But I want to statically link instead. I've tried this and all sorts of similar commands:
    g++ -I/usr/local/include/boost-1_35 -o test test.cpp -lboost_filesystem-gcc42-mt-s-1_35 -static -static-libgcc
    and I'm always getting these linker errors:
    Code:
    /tmp/ccoiFv2v.o: In function `__static_initialization_and_destruction_0(int, int)':
    test.cpp:(.text+0x1dc): undefined reference to `boost::system::get_system_category()'
    test.cpp:(.text+0x1e6): undefined reference to `boost::system::get_posix_category()'
    test.cpp:(.text+0x1f0): undefined reference to `boost::system::get_posix_category()'
    test.cpp:(.text+0x1fa): undefined reference to  `boost::system::get_system_category()'
    collect2: ld returned 1 exit status
    I've built Boost in full, and have got these Boost.Filesystem libraries in /usr/local/lib:
    libboost_filesystem-gcc42-1_35.a
    libboost_filesystem-gcc42-1_35.so
    libboost_filesystem-gcc42-1_35.so.1.35.0
    libboost_filesystem-gcc42.a
    libboost_filesystem-gcc42-d-1_35.a
    libboost_filesystem-gcc42-d-1_35.so
    libboost_filesystem-gcc42-d-1_35.so.1.35.0
    libboost_filesystem-gcc42-d.a
    libboost_filesystem-gcc42-d.so
    libboost_filesystem-gcc42-mt-1_35.a
    libboost_filesystem-gcc42-mt-1_35.so
    libboost_filesystem-gcc42-mt-1_35.so.1.35.0
    libboost_filesystem-gcc42-mt.a
    libboost_filesystem-gcc42-mt-d-1_35.a
    libboost_filesystem-gcc42-mt-d-1_35.so
    libboost_filesystem-gcc42-mt-d-1_35.so.1.35.0
    libboost_filesystem-gcc42-mt-d.a
    libboost_filesystem-gcc42-mt-d.so
    libboost_filesystem-gcc42-mt-s-1_35.a
    libboost_filesystem-gcc42-mt-s.a
    libboost_filesystem-gcc42-mt-sd-1_35.a
    libboost_filesystem-gcc42-mt-sd.a
    libboost_filesystem-gcc42-mt.so
    libboost_filesystem-gcc42-s-1_35.a
    libboost_filesystem-gcc42-s.a
    libboost_filesystem-gcc42-sd-1_35.a
    libboost_filesystem-gcc42-sd.a
    libboost_filesystem-gcc42.so
    I hope someone can help me because I just can't see what I'm doing wrong!

    Thanks in advance,

    cal
    Stupid Creatures Free for Android phones and tablets: https://play.google.com/store/apps/d...dcreaturesfree

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,248
    Distro
    Kubuntu

    Re: C++/Boost linker errors

    I believe the -static should come before the -l option.

    Also, what is the difference between these libraries? Are you certain you are specifying the correct one?
    • libboost_filesystem-gcc42-1_35.a
    • libboost_filesystem-gcc42.a
    • libboost_filesystem-gcc42-d-1_35.a
    • libboost_filesystem-gcc42-d.a
    • libboost_filesystem-gcc42-mt-1_35.a
    • libboost_filesystem-gcc42-mt.a
    • libboost_filesystem-gcc42-mt-d-1_35.a
    • libboost_filesystem-gcc42-mt-d.a
    • libboost_filesystem-gcc42-mt-s-1_35.a
    • libboost_filesystem-gcc42-mt-s.a
    • libboost_filesystem-gcc42-mt-sd-1_35.a
    • libboost_filesystem-gcc42-mt-sd.a
    • libboost_filesystem-gcc42-s-1_35.a
    • libboost_filesystem-gcc42-s.a
    • libboost_filesystem-gcc42-sd-1_35.a
    • libboost_filesystem-gcc42-sd.a

  3. #3
    Join Date
    May 2008
    Location
    UK
    Beans
    15
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: C++/Boost linker errors

    If anyone's interested...
    I had to link to boost_system-gcc42-mt-1_35 too - D'oh!!!
    (The clue is in the linker errors - boost::system::get_system_category() etc.)

    So the correct build command is:
    g++ -I/usr/local/include/boost-1_35 -o test test.cpp -lboost_filesystem-gcc42-mt-s-1_35 -lboost_system-gcc42-mt-s-1_35 -static
    Stupid Creatures Free for Android phones and tablets: https://play.google.com/store/apps/d...dcreaturesfree

  4. #4
    Join Date
    Jul 2008
    Location
    Dublin, Ireland
    Beans
    633
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: C++/Boost linker errors

    Quote Originally Posted by calzakk View Post
    But I want to statically link instead. I've tried this and all sorts of similar commands:
    g++ -I/usr/local/include/boost-1_35 -o test test.cpp -lboost_filesystem-gcc42-mt-s-1_35 -static -static-libgcc
    Try giving the full name of the lib as in:
    g++ -I/usr/local/include/boost-1_35 -o test test.cpp -l:libboost_filesystem-gcc42-mt-s-1_35.a -static -static-libgcc

  5. #5
    Join Date
    Aug 2010
    Beans
    23

    Re: C++/Boost linker errors

    I had a very similar problem and found this post while searching. I managed to solved the problem after much more searching, so I post it here for other people.

    I had to link to the proper library this way:
    g++ boost_example.cpp -o run -lboost_filesystem-mt
    http://linux.overshoot.tv/ticket/127

    The real problem is that the boost documentation is lacking and does not say which library to link to. See:
    http://linux.overshoot.tv/ticket/129

    Anyway, to use boost/file_system, link to: -lboost_filesystem-mt .

    See also:
    http://ubuntuforums.org/showthread.php?t=244593

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •