CMake Boost 1.59.0 geometry - c++

I am fairly new to using boost along with C++. I have just installed Boost 1.59.0 and I want to use the geometry library.
If I include FIND_PACKAGE( Boost 1.47 REQUIRED ) it finds boost and no problems arises. If I then include FIND_PACKAGE( Boost 1.47 COMPONENTS geometry REQUIRED ) I get the following error:
Unable to find the requested Boost libraries.
Boost version: 1.59.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_geometry
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
If I run the following [ -f /usr/include/boost/geometry/geometry.hpp ] && echo "Found" || echo "Not found" in the CLI I get Found as a result. So it seems that it's there, but CMake tells me it's not.
What am I misunderstanding?

COMPONENTS is required only for built libraries. Geometry is an header-only library so it's not needed. You need only to find the boost headers location.

Related

Boost 1.69 and CMake 3.13

I have just updated my MSYS2 and received a new version of boost library 1.69.0. But after this update CMake 3.13.1 that must support this boost version says to me:
CMake Error at C:/Program Files/JetBrains/CLion 2018.2.6/bin/cmake/win/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.
Boost version: 1.69.0
Boost include path: D:/msys64/mingw64/include
Could not find the following Boost libraries:
boost_chrono
boost_filesystem
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
As i see CMake found boost 1.69.0 but not found Boost libraries. Why? With Boost 1.68.0 all works perfect.
PROBLEM SOLVED:
Today i cheked updates in MSYS and received an updated package
mingw-w64-x86_64-boost-1.69.0-2
After that CMake found all Boost 1.69.0 libraries succesfuly

Compiling C++ with Boost 1.68.0 on Windows using CMake and MinGW

I want to use the Boost library on Windows but doing so has been troublesome. I downloaded the Windows package from here and extracted it to C:\Boost:
I added the following to my CMake file:
find_package(Boost 1.68 REQUIRED COMPONENTS filesystem)
# ...
target_link_libraries(MyExecutable ${Boost_LIBRARIES})
I'm getting the following CMake error:
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" "-DCMAKE_C_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe" -G "CodeBlocks - MinGW Makefiles" D:\Cpp\MyProject
CMake Error at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: C:/Boost
Could not find the following Boost libraries:
boost_filesystem
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
-- Configuring incomplete, errors occurred!
See also "D:/Cpp/MyProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Failed to reload]
It apparently cannot find filesystem but it's there in C:\Boost\boost\filesystem (here is the documentation on FindBoost).
How do I setup my CMake file to use Boost properly? I tried setting the Boost environment variables as well but it still didn't work:
SET (BOOST_ROOT "c:/Boost")
SET (BOOST_INCLUDEDIR "c:/Boost/boost")
SET (BOOST_LIBRARYDIR "c:/Boost/libs")
FIND_PACKAGE(Boost 1.68.0 REQUIRED COMPONENTS filesystem)
Also, Boost says that most things don't have to be compiled so I didn't do that.
It cannot find the library boost::filesystem. Because boost::filesystem is one of the few libraries that need to be compiled (all the ones that you have to specify in the find package command have to be compiled).
You need to build boost first:
./booststrap.sh
And then:
bjam
It picks up whatever compiler is available, so you may have to set the proper toolset manually.
Not completely related, but I think your link line is incorrect, instead of:
target_link_libraries(MyExecutable Boost::filesystem)
it should say:
target_link_libraries(MyExecutable ${Boost_LIBRARIES})
Boost_LIBRARIES is automatically defined once Boost is found, so it's for free.
The CMake FindBoost macro only fills Boost_Libraries if the find_package contains a COMPONENTS section and the macro actually finds those libraries on disk.
So here I'd be saying I need Boost to be found AND it must have filesystem
find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem)
The macro then tries to construct a bunch of potential filenames for the filesystem (taking into account if I want shared version, debug, multi-threaded etc.) and searches for those names under Boost_ROOT. If it doesn't find the file it may error and won't fill out Boost_Libraries.
If in doubt, add a line like this to your CMake prior to find_packages() to see what libs the macro is looking for and compare to what you actually have:
set (Boost_DEBUG ON)
For me I discovered that I had a Boost that placed an -x32 and -x64 architecture version of the libs, e.g. "libboost_system-mgw92-mt-x64-1_66.a". The macro wasn't filling in the architecture prefix into the filename it was looking for and failed.
I had to add a line like this to give the macro a clue which version I wanted:
set (Boost_ARCHITECTURE "-x64")
After that ${Boost_Libraries} expanded correctly and I was able to correctly use it to link.

Cannot find boost libraries with cmake

I've install boost 1.63.0 on Windows and I am trying to build with CMake (using Visual Studio 2017 as a generator). I'm having trouble getting find_package() to find my boost libraries and I can't figure out why.
CMakeLists.txt:
find_package(Boost REQUIRED COMPONENTS system filesystem thread)
Output:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.8/Modules/FindBoost.cm
ake:1813 (message):
Unable to find the requested Boost libraries.
Boost version: 1.63.0
Boost include path: C:/Program Files (x86)/boost/boost_1_63_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
boost_thread
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Boost finds the includes, but not the libraries. Headers are located at:
%BOOST_ROOT%. Libraries are located at %BOOST_ROOT%/stage/lib. When I look at _boost_LIBRARY_SEARCH_DIRS_RELEASE, the first place it looks is the correct location. I've also tried hard-coding BOOST_LIBRARYDIR to that path just to be sure.
To install boost I extracted the downloaded archive to %BOOST_ROOT%, then ran bootstrap and .\b2 link=static,shared threading=single,multi. This should give me all versions of the libraries. In the case of boost:system, I have the following binaries in %BOOST_ROOT%/stage/lib%:
boost_system-vc100-mt-1_63.dll
boost_system-vc100-mt-1_63.lib
boost_system-vc100-mt-gd-1_63.dll
boost_system-vc100-mt-gd-1_63.lib
libboost_system-vc100-mt-1_63.lib
libboost_system-vc100-mt-gd-1_63.lib
I've tried enabling and disabling the following, but to no avail:
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_DEBUG ON )
Here is an interesting part. The Boost_DEBUG parameter spits out this line:
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_63;boost_system-vc141-mt;boost_system-mt-1_63;boost_system-mt;boost_system
Note the vc141 versus vc100. I think .\b2 built something for vc100. That's strange because I was running it from the Dev Command Prompt for VS 2017. I've taken a wild guess and tried to build boost with ./b2 toolset=msvc-14.1 but I get an error: *** argument error * rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )".
How can I ensure that I compile boost with VS2017 or MSVC141?
This thread seems related:
Version numbers for Visual Studio 2017, Boost and CMake
Check the FindBoost.cmake script that is being used. Depending on the version of CMake you use, this version of Boost may not be handled. The dependencies between libraries is set depending on the version of Boost found.
For example the latest version of the script in CMake sources on GitHub handles version 1.63. I had the problem with CMake v3.6.2 which does not handle it.
Regarding the version mismatch for MSVC I don't know, sorry.
I compiled boost, and am compiling the linking application with the same toolset. Therefore I decided that it was safe to simply rename all compiled libs from *-vc100-* to *-vc141-*. While normally I would discourage that (you could get subtle differences in the ABI), in this case I was certain that it was the same compiler and so it's clear that either cmake or b2 had a bug which created(or searched) a file with the wrong name.
After doing that, cmake not only found boost, but linked successfully.

C++ Unable to find the requested Boost libraries

I'm trying to add Boost to my C++ project using CMake but it refuses to find Boost libraries eventhough I am 100% sure they are there.
Error:Unable to find the requested Boost libraries.
Boost version: 1.61.0
Boost include path: C:/Program Files (x86)/boost_1_61_0
Could not find the following Boost libraries:
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
This is what my search looks like in CMake.
FIND_PACKAGE(Boost REQUIRED COMPONENTS system)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
I have tried to set all of the paths manually but nothing changes and it keeps telling me no libraries could be found.
EDIT:
To clarify, if I remove "COMPONENTS system" it will not error but crash on the build, giving
"undefined reference to `boost::system::generic_category()'"
, etc.
EDIT 2:
I want to clarify a bit more, I am able to use header only parts of boost, but I cannot use anything else, as it will give me the undefined reference error. I searched Stackoverflow for that error, and the solution was adding the "COMPONENTS system" part to find_package, and that's where it goes wrong.

CMake with boost( on windows) :Could not find libraries?

I am trying to build my project using CMake. Iam also using boost.
The find package statement in my CMakeLists.txt file is:
find_package(Boost 1.42 REQUIRED COMPONENTS
python
system
filesystem
serialization
thread
program_options
regex
test_exec_monitor
)
The build fails and the error message i get is:
The following Boost libraries could not be found:
boost_system
boost_filesystem
boost_serialization
boost_thread
boost_program_options
When i check my lib directories i find that the libraries are by name:
libboost< library_name >-vc100-mt.lib and not by boost_< Library_name >
Infact when i rename a single library in my lib files to fit according the boost_< LibraryName > Prefix, it doesn't complain for that library.
I see 2 solutions for the same:
1.Make changes in the CMakeLists.txt file so that it searches for libraries with correct Prefix( and suffix ).
2.Others
What could be the best one.
From the FindBoost.cmake
These last three variables are available also as environment variables:
Also, note they are completely UPPERCASE, except Boost_DIR.
Boost_DIR or The preferred installation prefix for searching for
BOOST_ROOT or BOOSTROOT Boost. Set this if the module has problems finding the proper Boost installation.
Use these variables to point on folder where your boost libs installed. For example
cmake .. -DBOOST_ROOT=C:/Boost