How to configure Boost with Netbeans 6.9 on Ubuntu - regex

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?

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.

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.

Related

NetBeans C++: Linker Can't Find External Libraries Specified in Linker Options

I've been trying to learn how to use NetBeans as a C++ development environment. I installed NetBeans 8.2, installed MinGW, and compiled a simple Hello World program to make sure everything works. I then decided to try to compiler an old OpenGL project (based on this tutorial) that I had up-and-running in Visual Studio. Unfortunately, I keep getting errors saying the linker can't find the glew32 or glut32 library files:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglew32
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglut32
As best as I can tell, however, I've set all of the necessary linker options;
screen-shot here.
What am I missing here?
My project's compile command as stated in the output pane:
g++ -o dist/Debug/MinGW32-Windows/opengl_tutorial build/Debug/MinGW32-Windows/nbproject/Main.o build/Debug/MinGW32-Windows/nbproject/ReadTGA.o -L\"C\:/C++\ Libraries/glew-1.13.0/lib/Release/Win32\" -L\"C\:/MinGW/lib\" -L\"C\:/C++\ Libraries/glut-3.7/lib\" -lglew32 -lglut32 -lglu32 -lopengl32
Things I've Tried
Removing spaces from external libraries' file path.
Placing .lib files in MinGW's lib folder (this gets rid of the original error and results in a slew of undefined reference errors).
Adding each library's bin folder to the Aditional Library Directories list and adding the DLLs to the Libraries list.
Switching between putting the file paths in the Aditional Library Directories list in quotes and not putting them in quotes (without quotes I get undefined reference errors).
Additional System Information
Operating System: Windows 7 Home Premium 64-bit SP1
Processor: 2GHz Intel Pentium Dual-Core
Try Adding environmental variables in
Properties->Run->Environment
In my case
Name=LD_LIBRARY_PATH
Value=/usr/local/apps/Java/jdk-14/lib:/usr/local/apps/root6.22.02Install/lib/root:/Work/Soft/general_classes/lib (and some more paths which no need to be pasted here)

add armadillo libraries to g++ compiler in linux

I am trying to install a C++ library (armadillo) in a unix cluster where I do not have root permissions.
I managed to compile the C++ libraries without user permissions by running the following make command:
make install DESTDIR=my_usr_dir
But then in the armadillo readme file it says:
where "my_usr_dir" is for storing C++ headers and library files. Make sure your C++ compiler is configured to use the sub-directories present within this directory.
The compiler the armadillo uses to install the libraries is gcc-4.8.1. I am not sure where the compiler was installed but it's loaded when I start my session in the unix cluster.
After installing armadillo I am trying to compile open source code that uses the armadillo libraries. This open source code also has a makefile.
However, when I go to the open source code and I type in:
make
it calls g++. How can I make sure g++ will recognize the armadillo libraries previously installed in my_usr_dir?
Currently I get the following error if I go to src and then type make:
opencode.cpp:28:21: fatal error: armadillo: No such file or directory
#include <armadillo>
^
compilation terminated.
make: *** [mmcollapse] Error 1
you can use
alias gcc="gcc -I./my_usr_dir/include -L./my_usr_dir/lib"
and so on in your .bashrc file. In that way, whenever you invoke gcc on the command line, the flags will be added before every other argument you enter on the command line
I think the readme file refers to the usage of the library headers and library files from applications. For those to be useful, the compiler/linker/loader (usually all driven by the "compiler") have to know where to find them. The compiler always looks in some default directories, such as /usr/include (for headers) and /usr/lib/ (for libraries), but they require root permission to write into. However, you can tell the compiler with the flag -Idirectory to search in directory directory for headers. For libraries use -l and -L (check the manual page of your compiler). You may also need to consider the LD_LIBRARY_PATH and LD_RUN_PATH environment variables, if you're using dynamic linking (shared object files).
This question looks similar to
How to specify non-default shared-library path in GCC Linux? Getting "error while loading shared libraries" when running
If you dont want to change the .bashrc
use -rpath as suggested in the post above.
gcc XXX.c -o xxx.out -Lmy_usr_dir -lXX -Wl,-rpath=my_usr_dir
-L is for static linking
-rpath for adding the directory to the linker search path
more on -rpath here
I don't understand -Wl,-rpath -Wl,
Dont bother to upvote the answer because this is really not an answer. I would have commented but i could not locate the add comment for your post.

Boost library eclipse linking error

I'm working on windows 7 and eclipse juno. In my project i have linked correctly header-only boost libraries, and i need only two compiled libs ("libboost_signals-mgw46-mt-1_54.a" and "libboost_signals-mgw46-mt-d-1_54.a"). I added them to the MinGW C++ linker in the same way is explained here Linking Boost to my C++ project in Eclipse. The path i have specified in "Library search path" for the linker is "C:\MinGW\boost_1_54_0\stage\lib" (where compiled libraries reside) and the libraries themselves are added with their names except the ".a". But when i try to build the project i get this error:
Info: Internal Builder is used for build
g++ "-LC:\MinGW\boost_1_54_0\boost" -o Ccccc.exe "src\Ccccc.o" -llibboost_signals- mgw46-mt-1_54 -llibboost_signals-mgw46-mt-d-1_54
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find - llibboost_signals-mgw46-mt-1_54
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -llibboost_signals-mgw46-mt-d-1_54
collect2: ld returned 1 exit status
The code is irrelevant because in order to solve this problem i try to add those libraries to a simply "Hello world" project. Thanks for any help, sorry for my english.
Just a wild guess but try omitting the lib from the library name to see if it can find the library that way. Otherwise, clearly the library cannot be found in your library path.

Compiler unable to find valid library path

I'm getting the following error:
ld.exe||cannot find -lD:\Libraries\boost_1_47_0\boost_1_47_0\stage\lib|
Even though the path is valid. Any thoughts on that?
Edit:
Thanks MichalR!
For others, in order to configure boost for gcc:
Download boost
install it according to instructions from boost site
In code::blocks in Settings/global variables add path to your boost library for base and lib fields (this should be located in stage/lib folder)
In code::blocks in Project/Build options..., linker settings tab, link libraries - add here those libraries
In code::blocks in Project/Build options...Search directories tab in compiler subtab add $(#boost) and in linker subtab add $(#boost.lib).
Done. I spent a few days on this, but it was worth it. Now I can use this great IDE with gcc compiler which at the moment of this writing is miles ahead of MS. I am not being stopped in my personal development by MS - C++11 here I come!
The params for ld are e.g.:
-larchive
-Lsearch_path
The first tells what library to look for, the latter specifies library search paths.
Perhaps you have these options mixed in your command line - it looks you have -l with a directory parameter.

How to use SOCI C++ Database library?

I'm trying to implement soci in my program but I don't know how. I'm using C++ on Linux, on a project using netbeans. I have followed the steps in: http://soci.sourceforge.net/doc/structure.html to install it, and I tried to copy the files soci.h from /src/core and soci-mysql.h from /src/backends/mysql in my project but it gives a compilation error (these files include other soci files, but it's illogical to copy all files into the directory...). I have read the guide several time but I don't understand what I'm doing wrong. The examples only include these files.
Thanks.
Edit: I have given more information in a comment below the answer. I don't know what steps I have to follow to implement soci.
The relevant bit on that page is
When the configure script is run without parameters, the remaining part of the process will use /usr/local/include/soci as a default destination for SOCI header files and /usr/local/lib as a default destination for library files
Now /usr/local/include ought to be in your default include path (e.g. try something like gcc -c -v -x c++ /dev/null -o /dev/null to see the list your install uses) and so you can include these using
#include <soci/soci.h>
#include <soci/soci-mysql.h>
You then need to add the libraries to your link step. It looks like you'll have both static and shared versions of the libraries. You'll need to add -lsoci_core -lsoci_mysql to your link step; however if that doesn't work then you'll also need to specify /usr/local/lib as a search directory i.e. -L/usr/local/lib -lsoci_core -lsoci_mysql. (Again it's probably there already but you can see using gcc -print-search-dirs.) However, the issue then is that if you're using the shared version and /usr/local/lib isn't in your distributions library search path (see /etc/ld.so.conf and/or /etc/ld.so.conf.d/*) then it won't be able to find the shared library at runtime. You'll need to either hard-code in the path to the library with the linker switch -rpath or add /usr/local/lib to the system-wide search path as before or in your environment (variable LD_LIBRARY_PATH). I'm not sure what the best way to do this is - I'd suggest -rpath to avoid modifying the system in general, although if you're building a lot of libraries into /usr/local/lib it might make sense to add it.
I got the same doesn't load backend error on my C++ program when I execute session sql("mysql://db=...)
I found a solution (at least on my Ubuntu 11.04). Just do:
sudo -i ln -s /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so /usr/lib/libsoci_mysql.so
It seem that the SOCI library search for the file /usr/lib/libsoci_mysql.so that is not in the system, buy if you make a link to the library /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so that it's in the system it works (I think debian/ubuntu makes a file name change from the original name, but it have side effects because the SOCI library search inside for the original name).
I found the error using the bash environment variable LD_DEBUG=files and running my C++ binary.
Hope it helps.