G++ Can't Find Boost Libraries. I Say They'Re in Plain Sight

G++ can't find boost libraries. I say they're in plain sight

Try putting the libraries after main.cpp.

I've experienced some weirdness in the past when GCC ignores libraries because it doesn't think they're used, before reaching my source files.

Cmake doesn't find Boost

Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt:

FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()

If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")

Of course, those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt.

CMake fails to find boost libraries (CGAL, Windows)

Alright, I finally got everything to the state I needed. What follows is essentially a description of how to get the magical libCGAL.dll and libCGAL.a (library files) that you want on Windows 7 with Code::Blocks.

  1. I downloaded and installed CMake.
  2. I downloaded and installed Boost 1.58.0, with the manual and GMP included (but not examples because I don't want to flub around with Qt). The destination was a folder without spaces.
  3. I downloaded and installed CGAL-4.6. Again, destination was folder without spaces.
  4. I added CodeBlocks\MingW\bin to my PATH environmental variable.
  5. I went into the boost_1_58_0 folder, opened a command prompt, and typed bootstrap gcc, followed by b2 --toolset=gcc, all good. This seemed to build Boost into the stage\lib folder.
  6. I made a new Code::Blocks project to test the Boost files. In the projects Build Options, I selected the root, added under Linker Settings a direct path to the libboost_regex-mgw44-mt-1_58.a, under Search Directories I added under Compiler the boost_1_58_0 folder, under Linker the boost_1_58_0\stage\lib folder. I then successfully compiled and ran the example regex program here (section 6).
  7. I went into the CGAL-4.6 folder and opened a command prompt. I typed cmake-gui. I followed this tutorial to the letter, except that I (think) I chose "Specify native compilers" and pointed them to mingw32-gcc.exe and mingw32-g++.exe in the MingW folder (it might work with the first option if you've added MingW\bin to the path like you have to anyway, later)
  8. After configuring and building correctly, a Code::Blocks project file was created, along with a Makefile. The Code::Blocks file was useless and wouldn't build correctly because it tried to run make.exe instead of mingw32-make.exe. I had no idea how to fix this, so I simply went to my Code::Blocks folder, opened a command prompt and typed mingw32-make.exe -s -f <path-to-the-makefile> all. It Make'd without problems.
  9. Finally, I made a test project. Like in Step 6, I added ALL the non-debug libraries from Boost (blah-blah-NOT-d.a in stage/lib) and the libCGAL.dll.a library from CGAL-4.6\lib. I added also the Boost directories as in Step 6, and the CGAL-4.6\include directory too.
  10. Super-finally, I compiled the example here without problems. Before running it. I had to move CGAL-4.6\bin\libCGAL.dll into the exe file folder, that is bin\Debug.

NOW THAT WAS PERFECTLY STRAIGHTFORWARD, WASN'T IT?!

If someone else gets stuck on this, throw a message and I can shoot you the actual files everyone wants: libCGAL.dll, libCGAL.dll.a, all the Boost library files and all the headers.

Linking boost in CLion project

I found the whole story, and I'm writing down the solution in case someone a little lost like me needs it.

So if you want to link boost to a project on windows using cmake with mingw as compiler, first you need to download and install mingw, with posix threads, and of cours x86_64 architecture. Then you download the boost sources and you can follow this tutorial in order to build Boost. Building Boost is mandatory for most of the boost libraries. By the way, to add things to windows PATH you need to go to Control Panel > System and Security > System > Advanced parameters > Environment variables and there you edit the PATH variable (you might want to add the mingw/bin folder to PATH). The last step will take a somewhat long time.

Once you have build your libraries, what you want to do is to link them on your CMakeLists.txt file. This is the code you want to add to the file :

set(Boost_ARCHITECTURE -x64)
set(BOOST_ROOT <path/to/boost>)
set(BOOST_INCLUDEDIR <path/to/boost/includes>)
set(BOOST_LIBRARYDIR <path/to/boost/lib>)
set(BOOST_NO_SYSTEM_PATHS ON)
find_package(Boost COMPONENTS <the components you want to load>)
include_directories(${Boost_INCLUDE_DIRS})

add_executable(your_project main.cpp)

target_link_libraries(untitled ${Boost_LIBRARIES})

So there is something up there that you won't find on FindBoost doc which is the Boost_ARCHITECTURE variable, which for some reason is not specified. The thing is that the lib files produced by the boost build will be named like this :
libboost_atomic-mgw81-mt-x64-1_71.a, but by default FindBoost will look for names such as boost_atomic-mgw81-mt-1_71, which it will never find since all the names have the architecture in it. So to enable FindBoost to search for .a files with -x64 (or -x32) in their name you need to add the set(Boost_ARCHITECTURE -x64) line, otherwise cmake will tell you that it did not find Boost.

C++ CMake cannot find Boost 1.63 (using CLion IDE)

After researching for a few days, installing and uninstalling tons of times, it turns out that I was just mistaking one line:

set(BOOST_INCLUDEDIR C:/boost/include/boost-1_63)

That is it! Oh my GOD.

Trouble setting up Boost library with GCC-6 in Clion

I was able to fix this issue.

I realized my Boost libraries were not installed properly.

For some reason, Homebrew does not install Boost libraries properly and you've got to install it the way it's mentioned in their documentation.

Getting Started on Unix Variants

StackOverflow question How do you install Boost on MacOS?

Thanks to snies answer https://stackoverflow.com/a/11297605/8093027.

Building CMake project with Boost libraries on GitHub Actions gives error Could NOT find Boost

github.com will give you a fresh runner for every job.

See here https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#using-a-github-hosted-runner for details.

Thus it is not possible to prepare the machine in one job and use it in a later job.

You should move the installation of the needed packages inside your build job.

In case you need to exchange artifacts, like binaries from one job to a later job, you should take a look at the github actions upload-artifact and download-artifact.

how to debug in c++

This is not a compile error btw, it's a linker error, you are not linking with regex library of boost (unlike most of Boost, regex is a compiled library so you need to link it). Better, drop boost::regex and just use std::regex (#include <regex>) which is part of standard library in C++11 (compile with -std=c++11), and all pain will go away.



Related Topics



Leave a reply



Submit