Boost Libraries on Monodevelop - c++

I am trying to link some Boost .hpp files with Monodevelop, but I don't know how to tell the IDE where Libraries are.
If I want to include the array.hpp file, I write #include<directories/array.hpp>, but because this file makes calls to other files, and the directories to those files in the array.hpp file are only /boost/somefile, there are several path errors. What can I do? Thanks in advance.

For libraries like Boost you'll need to add the path to the includes/libraries in your project configuration.
In MonoDevelop this can be done by choosing Project->Options->Configurations, then choose the appropriate build type (you'll probably want to edit both Debug and Release eventually), and then Code Generation->Paths.
The Library section is for your built libraries, if any, and the Include section is for stuff like headers and includes.
In this particular case you'll want to add /usr/local/boost to the Include section (change the path as necessary).
Once you've done that, you should be able to use Boost like so:
#include <boost/array.hpp> // make sure you use angle brackets

Related

How do you create a proper 'include' directory?

So, we have all seen (some of you guys might have even made) professional libraries which have proper include directories which contain all the header files you need to use the library. An example would be the OpenCV library include folder which I have attached.
When we release libraries, what we do is just zip the headers for the lib and ask the recipient to extract them to somewhere convenient, which is, to be honest, quite fine. However, I would like to make an 'include' directory with all relevant headers if possible because I feel that my distribution can be organized better that way. How can we go about doing that?
You can just create a folder for all neccessary headers and specify path considering that folder when include them in code.
You can also specify that folder in preferences of your project, for example Visual Studio or Eclipse allow it, so you shouldn't write full path for those includes.

Is there a way to add include directory from C++ code?

I have a project whose vcxproj file is auto generated prior of compilation by using a script during the build process.
this project dependes on a boost library which is installed in a known location on the build machine.
the project header file declares:
#include "boost/foreach.hpp"
which forces me to manually add the path to the boost root folder to the Additional Include Directories field in the vcxproj file.
As the project file is auto-generated it forces me to split the build process into two stages and edit the project file in between.
i have also tried to change the source file and add the full path in the #include statement:
#include "<path to boost root>/boost/foreach.hpp"
but then some boost internal include fails. Which means i can't proceed in this way.
I have read through Set #include directory from C++ code file to find there is no option to add the path from code.
As I'm now on VS2012/C++11 environment i wonder if anything changed in VS2012 / C++11?
Is it still impossible to add an Include directory using a code statement?
You mean dynamically? No, there is no way. The reason is simple:
When you are running your program, it's already compiled, hence the compiler has to know about all the files to include at compile time.
It seems you're using CMake. If that's the case, I recommend you to add the include dirs in the CMake file.
Firstly, doing this:
#include "<path to boost root>/boost/foreach.hpp"
should be strongly discouraged. By doing that, you're making your source code build-able only on your environment - as your project grows, it will be a nightmare to change the path, or for other developers to build it. And, as you discovered, you'll break any headers which are included further down the chain, which are using relative paths.
What kind of script is generating your project? Is it a custom one, or is it a well known build tool such as SCons or CMake? The correct solution is to fix your build script so that it generates the project with the additional include paths correctly.

How to include a C/C++ lib (e.g. libcurl) in a C++ project (IDE: Eclipse)?

I have a problem, I'm working on a C++ project (I'm using Eclipse as my IDE).
Now I want to make use of a C/C++ library, for example libcurl, so I download curl and don't know what to do next.
Must I only include the .h and .c files I need or must I compile it before?
A typical way to use a library (this, of course might differ from library to library) is to include all of the header files from the library, include them as needed, use functions that they provide. Then, when building the application, link the objects with the library object (.a, .lib, whatever the extension). If you don't have the .a or .lib file, then you should build that independently
You must compile it before, then include the h files in your include path (in the Eclipse project). You will also need to find out how to import the library that you compile into your Eclipse project.
Once all that is done, you can make calls to the library after #include'ing the appropriate headers.
Both ways are possible. Compiling to a library is probably easier.

Including Libraries C++

How do I properly include libraries in C++? I'm used to doing the standard libraries in C++ and my own .h files.
I'm trying to include wxWidgets or GTK+ in code::blocks and/or netbeans C/C++ plugin. I've included ALL libraries but I constantly get errors such as file not found when it is explicitly in the include!
One error: test1.cpp:1:24: wx/msw/wx.rc: No such file or directory : Yes the .h file library is included; what am I missing?
Do I need to be importing other things as well? Is there a tutorial for this? Obviously my shoddy textbook hasn't prepared me for this.
Firstly, header files are not the same thing as libraries. A header is a C++ text file containing declarations of things, while a library is a container for compiled, binary code.
When you #include a header file, the compiler/IDE needs to know where to find it. There is typically an IDE setting which tells the compiler where to look, or you can do it from the command line, normally using the -I switch. It sounds to me as if you have not set up the path to search for header files on in your IDE.
This means that test.cpp included "wx/msw/wx.rc" but that file cannot be found by your compiler. How to fix this depends on your compiler, but you need to find where wxwidgets is installed and add that to your "Include Paths" so that your compiler knows where to search for it. You can also put a more complete path to it in the include directive.
If the files are present in the same directory as test1.cpp, then probably you use the wrong kind of include. #include <...> is usually used for code that resides outside of the directory that your project is in. #include "..." is for includes inside your project directory (and then if they aren't found there, search in the same places as #include <> would).
It is quite an old question and this didn't really answer it for me.
I reinstalled wxwidgets into the root directory as someone suggested that being in a directory with a space in the name may be part of the problem.
Then I went into project > build options > search directories and removed all entries pointing to original install.
And this fixed the problem

How to add prebuilt library to a VC++ solution?

It's pretty easy to use a library in VC++ 2008 if you create a project for it and build it alongside the other projects in your solution, but what if the library has too complex of a build process and must be compiled separately via makefile?
My library is like that, and while I've had no problem compiling it on the command line, I have no clue what to do with the resulting header files and .lib file. I've put them all in one directory and added its path to my main project's Additional Include Directories, so it finds the header files just fine. I've also added the relevant info to Additional Library Directories and Additional Dependencies.
Perhaps there's another setting I'm forgetting to set besides these three? I'd appreciate all the help I can get. Thanks.
EDIT Here are the syntax errors I'm getting:
http://pastebin.com/m72ece684
Okay, based on those errors, it has nothing to do with finding your .lib files, it's choking on the header files.
Edit:
It looks like somewhere in windows.h, there is a macro definition for X942_DH_PARAMETERS which is breaking your dl_group.h.
Instead of putting your botan headers at top, but windows.h at top, and then right before you #include the botan headers add this line:
#undef X942_DH_PARAMETERS
Or as I just discovered, that macro is defined in wincrypt.h, and if you add NOCRYPT to your preprocessor definitions it won't include that file. Since you're using a third party crypto library you probably don't need wincrypt.
While I can't exactly say what your problem is I can offer some advice as to how to find a solution. I suggest creating a simple library that contains a single method and a single class, build it, and then try to successfully link it to your project. Once you get that done on a smaller scale, try repeating the steps with your original library.
For msvc compiler you can add
#pragma comment(lib, "MYLIBNAME.lib")
in your header. This will automatically make the linker look for "MYLIBNAME.lib" in the "Additional Library Directories".
If no longer an error occures
Can't find header ...
Can't find MYLIBNAME.lib
the problem is probably related to some other stuff like wrong C runtime, debug release mismatch, ...
P.S.: If the lib is in the solution tree just setting the dependency on the lib, will cause VS to add the targetpath to the libfolder and the libname to the libraries.