Linking Boost to my C++ project in Eclipse - c++

I'm trying to get the Boost library working in my C++ projects in Eclipse. I can successfully build when using header-only libraries in Boost such as the example simple program in the "Getting Started" guide using the lambda header.
I cannot get my project to successfully link to the regex Boost library as shown later in the guide. Under my project properties -> c/c++ build -> settings -> tool settings tab -> libraries, I have added "libboost_regex" to the Libraries box, and "C:\Program Files\boost\boost_1_42_0\bin.v2\libs" to the Library search path box since this is where all the .lib files are. I've even tried adding "libboost_regex-mgw34-mt-d-1_42.lib" to the libraries box instead of "libboost_regex" since that is the exact file name, but this did not work either.
I keep getting an error that says "cannot find -llibboost_regex" when I try to build my project. Any ideas as to how I can fix this?
Edit: on Windows XP, using mingw, and I have tried "boost_regex" as well..

I just went through the whole process of installing MinGW, compiling boost and installing Eclipse CDT and I'm able to compile simple programs using boost:regex. I'll write down all the steps. I hope that can be of help.
I've installed MinGW and MSYS in their default location.
Here are the step I took to build boost:
Download boost-jam-3.1.18-1-ntx86.zip from http://sourceforge.net/projects/boost/files/boost-jam
Put bjam.exe somewhere in your PATH
Unpack boost in C:\mingw\boost_1_42_0
Open an msys terminal window and cd /c/mingw/boost_1_42_0
In the boost directory run bjam --build-dir=build toolset=gcc stage
To configure Eclipse:
Add CDT to Eclipse 3.5 from the update site
Create a new C++ project
Under the Project menu select properties
Make sure the configuration is Debug [Active]
In "C/C++ General" > "Paths and Symbols"
Under the Includes tab select the GNU C++ language and add C:\MinGW\boost_1_42_0
Under the Library Paths tab add C:\MinGW\boost_1_42_0\stage\lib
In "C/C++ Build" > "Settings"
Select MinGW C++ Linker > Libraries
Click on the add button for Libraries (-l)
Type libboost_regex-mgw34-mt-d (without the .lib)
You can then go through the same steps for the Release configuration but use libboost_regex-mgw34-mt instead. Also make sure your source files include <boost/regex.hpp>

To link to boost library in eclipse you need to set both the eclipse's project library path(the one with the -L) and the name of the library(the one with the -l).
The prefix 'lib' and the extension of the library's name must be removed:-
eg: libboost_regex.a should be specified as boost_regex.

I believe your lib path is pointing to the wrong place. The libs will be installed to:
boost_install_dir\boost_1_42\lib
I think the default boost_install_dir is "C:\Program Files\Boost" (not sure because I don't use the default install directory).

Related

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

Adding openCV .dll files to Netbeans C++ Qt application

I am developing software where I need to use the OpenCV libraries under NetBeans. Took 2 days to be able to run correctly a C++ Application with OpenCV.
In a C++ Application I needed to add C:/OpenCV245/build/include in project properties->Build->C++ compiler-> Include Directories and Headers. Also, Under the Linker properties-> Additional Library Directories I had to add the following directories
C:/OpenCV245/release/lib
C:/OpenCV245/build/x64/mingw/lib
and add the .dll files I specifically needed in the linker->libraries
Now when I try to create a C++ Qt application, I add the proper include directories and headers but I can't add the path to my "additional libraries"...
I tried building to see what errors would pop:
cannot find -lopencv_core245.dll
cannot find -lopencv_highgui245.dll
How do we add .dll.a files to a C++ Qt application under Netbeans?
Programming environment:
NetBeans 7.4
MinGW 3.2 Compiler c++ compiler, msys make command and qt5.1.1 qmake for Qmake Command
Qt5.1.1
OpenCV2.4.5
Windows 8 64 bit
It appears as if you are trying to link with the *.DLL files instead of *.LIB files. The right way to go is to:
In the linker->libraries settings link to the *.LIB files you need instead of the *.DLL files.
Compile your program so you get an *.EXE
Put the relevant *.DLL-files in the same folder as the *.EXE
The program is now runnable if you double-click its icon in the file browser.
It the program refuses to run from Netbeans but it works from the file browser, then that is because you need to tell Netbeans what the "current working directory" is when you launch the program in debug mode. This setting should be available in some settings dialog.
+Under Project Properties-> Build -> Qt go to Expert Custom Definitions add add the path to the appropriate .dll.a files with the LIBS +=
+Under Project Properties-> Build -> C++ Compiler in Include Directories and Headers add the appropriate path for the includes. ex: C:\OpenCV\build\include
+Under Project Properties-> Build -> Linker click on Libraries then Add Library File... ( NOT ADD LIBRARY) and add the appropriate .dll.a files that were included in the first point.

GStreamer C++ on Visual Studio 2010?

Following instructions on http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows to install GStreamer and compile tutorials/examples on Windows 7, for compilation using Visual Studio 2010.
After installing the SDKs, I try to compile the "hello world" example...
Cannot open include file: 'gst/gst.h': No such file or directory.
Odd - the tutorials were supposedly configured with the paths to these files. Nevertheless, we can manually add them...
Add C:\gstreamer-sdk\0.10\x86\include\gstreamer-0.10 to project include directories
Cannot open include file: 'glib.h': No such file or directory
Add C:\gstreamer-sdk\0.10\x86\include\glib-2.0 to project include directories
Cannot open include file: 'glibconfig.h': No such file or directory
At this point it seems to be a dead-end, as there isn't a glibconfig.h file anywhere on PC.
Was some step missing from the gstreamer documents?
p.s. I see a similar question, but its accepted answer seems to be a dead-link.
This question was posted on 2014. However, for everyone that needs to install Gstreamer on Visual Studio , I am explaining how you configure your library on Windows.
First of you need to download the library from https://gstreamer.freedesktop.org/data/pkg/windows/
You need to download and install both installers for developers and non-developers.
For instance for 1.14 it is the now latest version,
gstreamer-1.0-devel-x86-1.14.1.msi
gstreamer-1.0-x86-1.14.1.msi
You will install and setup both of them in the same directory like C:\gstreamer. (I guess gstreamer automatically adds its /bin to the Path environment. If not just ask it.)
After that you will open your Visual Studio. Create your C++ project. Create your main.cpp file. Right click on your project and click properties.
We need to do 3 steps:
Include the necessary directory paths.
Define the where the .lib paths are.
Specify which .libs you want to use.
After clicking properties:
C/C++ -> Additional Include Directories -> define your include paths such as
C:\gstreamer\1.0\x86_64\lib\glib-2.0\include;C:\gstreamer\1.0\x86_64\include\gstreamer-1.0;C:\gstreamer\1.0\x86_64\include\glib-2.0\;C:\gstreamer\1.0\x86_64\include\glib-2.0\glib;%(AdditionalIncludeDirectories)
Linker -> General -> Adding Library Directories -> write your lib directory path such as
C:\gstreamer\1.0\x86_64\lib;%(AdditionalLibraryDirectories)
Linker -> Input -> Additional Dependencies -> Write your .lib files you want to use such as
gobject-2.0.lib;glib-2.0.lib;gstreamer-1.0.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
gobject-2.0.lib;glib-2.0.lib;gstreamer-1.0.lib are the ones we added, others are done by default.
That's all. You can just write in your main.cpp file
#include <gst/gst.h> and use your GStreamer Library
I think this will work for almost all libraries.
(1) Install Windows Driver Development Kit
(2) When creating new projects, use the "gstreamer" template in Visual Studio, rather than the "Windows application" template. Then it doesn't need anything changing in the include/linker settings to make #include <gst/gst.h> work properly.
The standard gstreamer installation on windows has a glibconfig.h located in: (assuming your gstreamer installation is in C:\gstreamer) C:\gstreamer\1.0\x86_64\lib\glib-2.0\include
The official way is using the "Property Sheet" feature of Visual Studio.
In Visual Studio, click View→Property Manager or View→Other Windows→Property Manager on the menu bar.
Click Property Manager tab near the Solution Explorer.
Right click your project name and choose Add Existing Property Sheet..., and navigate to %GSTREAMER_ROOT_X86%\share\vs\2010\libs and load gstreamer-1.0.props.
This will add Addittional Include Directories, Addittional Libraries Directories and Additional Dependencies to your Project Properties.
Build your project.
Sources:
Creating new projects manually:
https://gstreamer.freedesktop.org/documentation/installing/on-windows.html?gi-language=c#creating-new-projects-manually
Share or reuse Visual Studio project settings:
https://learn.microsoft.com/en-us/cpp/build/create-reusable-property-configurations

Can't add static library in Eclipse Juno 8.1.1 CDT C++ project

I have been trying to find a guide how to link a static library to my Eclipse CDT project but I was not able to find one. I have tried both with Visual Studio 2010 compiler and MiNGW.
I use Windows and Eclipse Juno 8.1.1 , under Project Settings -> C/C++ Build -> Settings I have something like this :
Lib manager :
Path and symbols:
You have to add the library name without lib and .a in Libraries (-l) and adding the path in Libraries search path (-L).
However, this question is resolved also in this stack.
Also in this site you can find a lot of usefull information and the explanation on how include linking library.
edit
As reported in the documentation:
Q. How do I add a static library file to a project? (Files such as libmtm.a)
A. First you will need to copy the file into your Eclipse project. You can do that by simply dragging it into the project folder in the "Project Explorer" tree in Eclipse.
To link the library (A static library is used similarly to an object file):
Open Project, Properties.
In that dialog select "C++ Build, Settings".
Under the Tool Settings tab choose "Linker" or "MinGW C Linker" or equivalent and under that select "Libraries".
Under "Libraries" press the "Add..." button (the green cross) and write the name of the library without the "lib" prefix and ".a" suffix. e.g. in order to link the library file libmtm.a write "mtm".
Under "Library search path" press the "Add..." button, select workspace and select the project.

fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_43.lib'

Made a new project, added main.cpp and wrote the code at this URL:
http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp
Also, added the appropriate include path.
What's next?!?!! It seems like a darn mystery to build a boost code!
Been digging on it for more than 10 hours.
Can anyone give a straightforward answer on how to build the boost library from the code under windows, VC9?
You need to use bjam. It is responsible for creating the libraries that your application will use. Once you use bjam, you are going to need to instruct your project to include the lib file. You do this by going into the project's properties -> Configuration Properties -> Linker -> General. Add the directory which created the lib file to Additional Library Directories. You should be capable of correctly linking after that.
I believe that this link describes the steps better than I could attempt in a post
#bogertron: I want to hug you! (:
So, at last, with a real head ache, I've managed to do so.
The exact steps I took, so others will be saved from the head ache:
Went to http://www.boost.org/doc/libs/1_43_0/more/getting_started/windows.html#or-build-binaries-from-source .
Followed the "5.3.1 Get bjam" clause. Downloaded the "pre-built bjam executable for your platform" at this URL: http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941 .
Extracted the ZIP file (my platform is Windows).
Ran "build.bat". It produced the file "bin.ntx86/bjam.exe".
Copied this file to my PATH ("...../boost_1_43_0/").
From a command line, executed "bjam.exe" and waited for about 4-5 minutes.
Then got this message at the console: "The Boost C++ Libraries were successfully built!"
That's it, it even tells you where the include & lib files are.
Not all Boost libraries are header only, Boost.System is one of them. The documentation for Boost.Asio tells you that it depends on Boost.System.
With Visual Studio, the Boost libraries use auto-linking, which means you don't have to explicitly link to the libraries you need. You however need to have the necessary libraries in the library search path, either globally or per-project.
If you don't want to build the Boost libraries yourself, you can use the installers provided by boostpro (only up to Boost 1.42 though at the moment). If you want to build them yourself instead, the documentation covers that well.
I had the same error and i followed the SourceForge. The link will take you to a folder of zipped lib and dll files for version of boost.You can download and unzip related library and when copied it to the related location everything gonna be alright ;)
In Visual Studio, right-click on your project, then go to properties and select:
Properties -> Configuration Properties -> Linker
There you add the full path of your library in the tab named "Additional Library Directories".
From the "Boost Getting Started Directions":
"5.2 Or, Simplified Build From Source
If you wish to build from source with Visual C++, you can use a simple build procedure described in this section. Open the command prompt and change your current directory to the Boost root directory. Then, type the following commands:
bootstrap
.\b2"
On Windows, I opened the Visual Studio Command Line from the start menu. First I types "bootstrap" and then I typed ".\b2".
Now with boost_1.50 the Boost.build is included in the zip file: check tools\build\v2\ or better read: ...boost_1_50_0/more/getting_started/windows.html