Adding Boost Library to a C++ project in OS X Eclipse

前端 未结 5 621
無奈伤痛
無奈伤痛 2021-02-06 02:41

I am have been attempting to get a C++ project setup using boost file system library using eclipse. I followed these directions to install boost on my system. The directions whe

相关标签:
5条回答
  • 2021-02-06 03:05

    I just ran into something very similar to this using eclipse and CDT... It turns out, using ubuntu and apt-get, libboost_system installs as libboost_system.1.40.0 in /usr/lib

    If you try to add it via the library tab in Helios it will complain because it is looking for *.so and *.s0.1.40.0 clearly doesn't match that. However after looking closely at what the linker was trying to doo, I just typed the raw string "boost_system" into the include path adder. This resulted in the linker doing a " -lboost_system" which is a format the linker knows how to deal with in resolving version dependency... If you instead put in the full path to the .so file, the linker will just complain because it tries to do a " -l/usr/lib/libboost_system.so.1.40.0" .

    So take my advice and just type in the simple " boost_system" after doing an apt-get install.. It will make it all very easy.

    0 讨论(0)
  • 2021-02-06 03:08

    Just wanted to be clear on what actually worked, since it was kinda pieced together from a few answers.

    1. Download the boost files and extract them to where you want to put them.
    2. In your terminal navigate to the directory and run ./bootstrap.sh
    3. When that is done run ./bjam (this takes a while so go smoke and get a cup of coffee)
    4. Open up your eclipse Project and go to Project > Properties > C/C++ Build > Settings
    5. Click on MacOS X C++ Linker > Libraries. You should see a split window with the top being for 'Libraries (-l)'. In this section add both boost_system and boost_filesystem. In the bottom section it should be for 'Library Search Path (-L)'. Here you want to put the path to the stage/lib directory inside where you extracted the boost download. It should look similar to below:alt text
    6. Click GCC C++ Compiler > Includes. This will be a single pane where it says 'Include Paths (-I)', well I think it is an I as he font is weird and could be a lower case l also. Anyway in that section add the path to where you put boost without the stage/lib part. It should look like below:alt text

    Everything should compile now with out a problem, and if you need to use any other boost libraries it should be just a matter of adding it to the linker section where boost_filesystem and boost_system are. Enjoy.

    0 讨论(0)
  • 2021-02-06 03:11

    Not sure where you do this in Eclipse these days, but under the include paths for Eclipse should be the path to the main boost directory (/Users/jacobschoen/Library/boost_1_45_0?). The compiler line should have something like the following in it, I would think:

    Invoking: GCC C++ Compiler

    g++ -I/Users/jacobschoen/Library/boost_1_45_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD (etc..)

    Update: Looking at my system, the linker path on yours might be more appropriately:

    -I/Users/jacobschoen/Library/boost_1_45_0/stage/lib

    Depending, of course, upon how you've installed and built boost -- this is with my most recent attempt with a full source build. Depending upon how you obtained boost, this may or may not be different. I recently redid the boost on my Mac for 64 bit and haven't had much time to try it yet....

    0 讨论(0)
  • 2021-02-06 03:27

    I had recently uninstalled the boost rpm and installed Boost like how you did. I had no problems running Boost programs in Eclipse. I didn't add any extra parameters. Just installed boost and ran Boost programs. It works fine.

    Tried your program in the vi editor. Commented out everything in main

    #include <cstdio>
    #include <boost/filesystem.hpp>
    
    int main() {
        /*boost::filesystem::path path("/Users/schoen"); // random pathname
        bool result = boost::filesystem::is_directory(path);
        printf("Path is a directory : %d\n", result);*/
        return 0;
    }
    

    and it still gave this error:

    /tmp/cc7TAIYS.o: In function `__static_initialization_and_destruction_0(int, int)':
    test.cpp:(.text+0x29): undefined reference to `boost::system::get_system_category()'
    test.cpp:(.text+0x35): undefined reference to `boost::system::get_generic_category()'
    test.cpp:(.text+0x41): undefined reference to `boost::system::get_generic_category()'
    test.cpp:(.text+0x4d): undefined reference to `boost::system::get_generic_category()'
    test.cpp:(.text+0x59): undefined reference to `boost::system::get_system_category()'
    collect2: ld returned 1 exit status
    

    I'm puzzled. Boost programs work on my system, but your program's header files itself are giving a problem. I doubt it's a problem with Eclipse. It has to be something else.

    0 讨论(0)
  • 2021-02-06 03:30

    Add boost_system to the linker list, together with boost_filesystem.

    0 讨论(0)
提交回复
热议问题