How to configure Boost with Netbeans 6.9 on Ubuntu

2019-08-09 23:49发布

问题:

I have gcc 4.4.5 and the latest boost library. I want to use boost specifically for its regex library. I tried using the built in c++ regex functions but apparently they are not fully functional yet. I followed a tutorial online to set up netbeans.

I added /usr/include/boost to the c++ code assistance include directories. I then added -lboost_regex-mt to the build>linker>additional options area in the project configuration. but I still get this error:

/usr/bin/ld: cannot find -lboost_regex-mt
collect2: ld returned 1 exit status

This is the command thats being created by netbeans:

g++ -lboost_regex-mt -o dist/Debug/GNU-Linux-x86/examples01 build/Debug/GNU-Linux-x86/main.o  

I also tried doing it with -lboost-regex and -lboost-regex-st and the same error, with only the mt changed. I also tried running a file using regex objects through the terminal but still got the same error. Can anyone help with this problem? Or at least point me in the right direction?

回答1:

You have to set your project's "Additional Library Directories" so that it knows what other directories to look into for your libraries to link against.

Here's a screenshot from Netbeans' site here: http://netbeans.org/community/magazine/html/03/c++/

edit: note that this will affect the generated compiler command to have -L options which specify additional locations to look for library files.



回答2:

You need to tell g++ where to find the libraries. One way doing this is to append the location of boost's libraries to your LD_LIBRARY_PATH. Note that this is not the same as the header files (the .hpp files in the include directory) which you said you've already included in your project.