using c++ libraries in eclipse c++ project - c++

As a newbie who doesn't know much about c++ libraries and project build/link procedure, let me ask the following:
1- What is the difference between
Project -> Properties -> GCC C/C++ General -> Paths and Symbols -> Includes
and
Project -> Properties -> GCC C/C++ Build -> Settings -> GCC C++ Compiler -> Includes
2- When should I use which one for external libraries in my project?
3- I see that libraries come with an include folder with a bunch of header files in it. Some libraries need compilation vs others don't. What's the difference? Why?
4- In what case do i need to deal with the following
Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Libraries
because i see sometimes people specify this Libraies(-l) thing and sometimes don't but i have no idea when it is supposed to be specified and when not.

Related

How can one use Boost with Eclipse?

I'm having a lot of trouble installing Boost for use with Eclipse C++ (compiler MinGW).
I first tried downloading the zip at https://sourceforge.net/projects/boost/files/boost/1.61.0/. After it downloaded, I brought it to my second drive, extracted the files there, cd there, and then ran ./bootstrap.bat gcc, which appeared to run successfully.
Then, I ran b2 install --prefix="D:\boostfiles" toolset=gcc and it took about 30 minutes to create a lot of files starting with bin.v2 and ending with rst.
However, #include <boost/asio.hpp> still gives an error. Is there somewhere the files are supposed to be?
For reference, my file structure includes the original boost_1_61_0 extracted folder, a folder that boost was installed to called boostfiles, and a folder called PFiles that includes both eclipse and MinGW.
After doing what I originally posted to install and configure Boost, follow these simple steps:
Go to Project Settings -> C/C++ Build -> Settings:
C++ Compiler -> Includes -> Include paths -> Add...
Add "(directory)\include\boost_x_xx"
C++ Linker -> Libraries -> Library search path -> Add...
Add "(target_directory)\lib"
C++ Linker -> Libraries -> Libraries -> Add...
Add (name of library without beginning "lib" or ending ".a")
For example: libboost_system-mgw49-mt-1_61.a becomes boost_system-mgw49-mt-1_61.
Try adding Boost to the Include and Library search paths.
Go to Project Settings -> C/C++ Build -> Settings:
C++ Compiler -> Includes -> Include paths -> Add...
Add "<target_dir>\include\boost_x_xx"
C++ Linker -> Libraries -> Library search path -> Add...
Add "<target_dir>\lib"
I have the same issue and here is how it is solved.
The path to Boost libraries is ("C:\Program Files\boost\boost_1_62_0")
Go to Project Settings -> C/C++ Build -> Settings:
C++ Compiler -> Includes -> Include paths -> Add...
Add "C:\Program Files\boost\boost_1_62_0"
C++ Linker -> Libraries -> Library search path -> Add...
Add "C:\Program Files\boost\boost_1_62_0\libs"

Eclipse Indigo CDT code completion

I am using Eclipse CDT as IDE to develop my application which uses an external library for which I have access to the header files and libraries.
How can I setup my project properties such that I can get code completion (I have code completion for files which belong to my project, but not to the ones which are part of this external library).
I tried the following approach which unfortunately fails.
Project->Properties->C/C++ general->Path and symbols -> Includes
In Includes, I added the path to the header files.
Unfortunately, this does not seem to work.
So how can I setup my project such that, if I instanciate an object (from this external library) in my project, I can get code completion and see all available public methods?
thanks for your valuable help.
This works for me: Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> C++ -> CDT User Setting Entries -> Add

Linking errors when adding LibXML2 to project

I'm trying to add libxml2 to my c++ project in visual studio but when I attempt to build the project I get about 30 or so linking errors like the following
I know this is a pretty vague question, but can anyone point out what direction I should look to solve these errors?
Have you pointed the linker to the libxml2.lib file?
In Visual Studio it can be done in the project properties -
Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.
The path for the lib file can be specified in -
Project -> Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories.
I strongly doubt you downloaded the libxml2 for linux not for windows, please double check that.
In
Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies
you have to add the
.dll.a
files ONLY, no .a, .dll or .la files.
Then in the execution directory, the .dll files must be present. (Or SymLink'ed.)

Eclipse C/C++: Using static/shared library project in executable project

I think the title almost hits the point..
What I am trying to do is write a server. Here is the thing:
I want to separate separateable parts of the server into different projets. For example I wanted to create a Project "ServerNetworkStuff" and "ServerGameLogicStuff" into two projects which are static or shared libraries..
Now I want to create another Project "Server" that uses these two Projects as library.
Eclipse Projects:
- ServerNetworkStuff (static library)
- ServerGameLogicStuff (shared library)
- Server (using ServerNetworkStuff, ServerGameLogicStuff)
Is that even possible? Or is there any equivalent solution which doesn't force me to reinvent the wheel?
Thank you for your help!
EDIT:
If I add a reference to the active mode under "Project > Properties > C/C++ General > Paths and Symbols > References" it doesn't work. The compiler can't find the header files.. if I add the path to the header files I get "undefined reference" errors.
PARTLY SOLUTION:
*Okay it compiles now... but execution doesn't work at the moment..
What I did was first creating my projects "Server" (executable) and ServerNetwork (shared lib). After adding a ServerNetwork reference to Server there were a few things to do left.
I had to change my includes from
#include <include/ServerThread.hpp>
to
#include "ServerThread.hpp"
without meaning any shared libraries I am using in the project. Just changed it for the references of my own classes.
In my project Server that wants to use ServerNetwork I needed to add -lServerNetwork and -fPIC as parameter for g++.
And additionally the folder which the .so-file contains must be added to the library path (which Eclipse should do automatically if you add the specific project as reference).*
The Reference in Eclipse only works with open projects. I found the fastest way is to add or symlink the headers needed in the system path (/usr/local/include or similar) or just add the path to it, and doing the same with the library.
If you don't want to do that (which should be the best option), you still can add includes and libraries:
the -I path in Project Properties -> C/C++ General -> Path and Symbols -> Includes,
the -L libs' paths in Project Properties -> C/C++ General -> Path and Symbols -> Library Paths,
the -l libs in Project Properties -> C/C++ General -> Path and
Symbols -> Libraries.
Or by hand: the -I path in Project Properties -> C/C++ Build -> Settings -> [CGG/C/C++] Compiler -> Includes, and the -L -l libs in Project Properties -> C/C++ Build -> Settings -> C++ Linker -> Libraries.
Inclusion
Now you can #include either with <> or "" syntax (is a good practice to reserve the former to system libraries).
Iussues
You should have execution problems if you don't move/copy/symlink the libraries in default paths, for example with OSX, the solution is to export the non-default path just before execution (e.g. export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/non-default/lib/path for OSX).

How to get access to external libraries and header files VC10

I'm going to get a book that uses Xerces C++. I'm currently using VS 2010 ultimate, so the program doesn't miss any features. I've downloaded the precompiled binaries for windows x86 VC10. My question is what do I have to do to my environmental variables and files to be able to have Visual studio import the header files i.e. #include . I have no experience linking external libraries, so I need a simple explanation.
Right click on your project -> Properties -> C/C++ -> General -> Additional Include Directories
Include the path of Xerces include files.
For Lib Properties Linker -> General -> Additional Library Directories
Include the path of Xerces lib files.
In Linker -> General -> Input -> Additional dependencies
Add the libs required for linking.