Is there a way to use C++ boost libraries without having the set up an environment?
I am trying to use boost::split but am getting errors because boost::split could not find other dependent files.
I know how to set up the environment with CMake/VS, but this is just a light weight utility program, so there's no need to do that.
Is there a way to just use boost libraries on the fly?
I am aware that much of boost is header-only, but I have received the following error, which is confusing me:
C:\Development\Libraries\boost_1_50_0\boost\algorithm\string.hpp:18:60: fatal error: boost/algorithm/string/std_containe
rs_traits.hpp: No such file or directory
compilation terminated.
Well, obviously this will only work for header-only libraries. You need more stuff for the boost-libraries that come with files to link.
Now, I'm doing just that: I use some of the boost header libraries, none of the link libraries, and I don't need any preparation for that. EXCEPT that boost includes some of its headers with <filename> instead of "filename", so you HAVE to add the boost library directory to the search path for include files. Nothing else should be required.
EDIT: except possibly for an adjustment to your warning settings. Unfortunately, boost is not "warning clear", which conflicts with my -Werror and /WX switches. I had to disable some warnings globally because there were just too many of them (and warning pragmas don't work with precompiled headers on all platforms), and fixed a few inside the boost headers.
Related
I work with external C++ libraries (OpenFst). I add them into the include path so I can get IntelliSense, GoToDefinition/GoToDeclaration, etc.
Some of these external libraries include code smells and YCM diagnostic is reporting a lot of warnings.
I want to get warnings for the code I develop, but I want to suppress the warnings from the OpenFST library (and other libraries I use as a dependency).
Is there a way to keep the Intellisense and suppress Diagnostics for a specific library?
Link to my .ycm_extra_conf.py with OpenFst added to the include path
I finally realized this functionality needs to be supported by compilers.
The solution is to use '-isystemMY_EXTERNAL_LIBRARY' instead of '-IMYEXTERNAL_LIBRARY' in my .ycm_extra_conf.py
It is basically already answered here.
I'm using CLion as my IDE. I downloaded MinGW from here (comes with boost), extracted, installed and connected it to CLion successfully. Then I set my compiler flags in CMakeLists and when I compiled my program, I encounted hundreds of warnings coming from boost libraries (in this case - boost/lexical_cast.hpp).
I really want to use most, if not all, of these compiler flags, but I also don't want boost (which is for sure better written than any of my own programs) to generate that much noise.
Is there any way of disabling all warnings from particular header / library (maybe even namespace)?
You can add the include paths as SYSTEM instead of standard ones:
target_include_directories(target SYSTEM ${Boost_INCLUDE_DIR})
This only works for GCC and clang, as Visual Studio doesn't have a specific include flag for system paths.
In C++, does one need to copy any needed header files into the directory of the main C++ file?
Ex. I have OpenCV installed globally, and the Python bindings are working well. However, if I write:
#include "opencv2/highgui/highgui.hpp"
I receive a "not found" error. Do I need to copy these from their global install location to the project dir? I'm certain there must be a well-established set of practices for this, so I don't want to poke around in the dark on my own.
It depends on which operating system and build tool chain you are using, but as an example using linux, gcc and cmake, this article shows how to build with opencv.
http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
As you can see with the find_package directive, cmake is searching for the opencv include files.
Obviously, you can specify include path directly with g++ -I, but having cmake find it for you has the advantage that it will have a better chance of being found if you compile on a different system. It will also give you an error if it can't find the files.
Lastly, you should ensure that you have the "dev" files, as opposed to just the library. The dev files will have headers to include. While, the library will only have shared objects (*.so) and archives (*.a) that can be used for static or runtime linking.
If it is installed globally, you need to inform the compiler to look globally, i.e.,
#include <opencv2/highgui/highgui.hpp>
I have just downloaded the boost libraries from the boost website and extracted them to my desktop. I was hoping to just have a quick look at them and have them installed on my machine and perhaps use them in the future when I am more accustomed to C++.
When I extracted it, I was confused with all of the extracted files. There is all of the headers in the boost directory but tutorials mention running bootstrap.bat (I'm using Windows).
So I am asking this: do I simply extract the headers to my compilers include directory like normal to get boost up and running or do I need to do something else?
As I understand it from searching about, apparently "most" of boost is just templates and can be used simply by including the headers, but what about the rest?
Am I totally barking up the wrong tree?
Thanks for any help
Since you mentioned you run Windows, take a look at this automated installer:
► http://www.boostpro.com/download/
Also, some general advice:
do I simply extract the headers to my compilers include directory
No! Do not pollute your compiler's includes with third-party includes; make a separate directory specifically for a particular library. You'll then need to tell your specific IDE in what directory it can find the library headers.
I usually use boostpro's installer, it is less work. I vaguely remember having to set up the BOOST_ROOT environment variable on one of my systems to use it.
The libraries that contained compiled source should be included in the installer.
If you don't use the installer (or don't set up your build correctly), and try to use the libraries that need it you will likely get some linker errors when you try and compile your program. Usually if you take those linker errors and plop them in google it tells you pretty quick which libraries you need to include in your build system. I use CMake for that and have been very happy..
Just add the root boost directory to include paths of your compiler/IDE (so if you have Boost extracted to C:\Boost, the compiler will use that path, not C:\Boost\boost).
Don't do any copying of the boost folder to your compiler's include directory, because it may make upgrading Boost harder in the future.
Also if you plan to use any of boost's compiled libraries, add Boost's lib directory to compiler's library search paths. Configuring the compiling step is a matter of putting the right toolset parameter to boost's build tool. If you have your command line environment configured properly, bootstrap should run and compile the builder without any problems, and the Boost builder should properly detect your toolset, so no parameters will be necessary.
As you do such configuration only once every time you do a clean install of your favorite compiler, it's not as hard or daunting as it seems.
I'm writing a software that depends on the Poco c++ library. I can manage to compile the library on both Ubuntu and Windows, but only as static. That's fine since I want to use it statically. However, when I try to compile the program that depends on the libraries, I get an error similar to this (freely translated) :
Poco/RegularExpression.h: No such file or directory.
However, when I also explicitly tells the compiler where to look for the library's header files with the -I switch I get the following error instead (but maybe 20-30 similar lines) :
Undefined reference to (pthread_mutex...)
I've tried with a lot of different combinations, both directly with g++, and by using makefiles.
Am I supposed to include the paths to the libraries' header files, or have I somehow not succeeded to compile the libraries properly?
If I should include the paths, how can I get rid of the "undefined reference" error?
I'm pretty new with c++ programming so bear with me.
Thanks, Robert
This is very common error, I, too, suffer from it every now and then.
Did you include the .a to your project?
How do you include the headers? with <> or ""?
If the latter, make sure the files are in your include folder.
If first, make sure you have added the path to the files, or that they reside in g++'s global include folder
Is the library meant to be compiled as .so/.dll?
Normally if the library is meant to be dynamic, the static library only points to it.
Do you have included the dependencies the Poco itself requires? Like the -lpthread I think you are missing.
Try the -I option. In the target that has RegularExpression.h as a dependancy, try to include the directory that contains the above header file like so:
g++ -I/home/.../Poco <other options>