3

I am developing C++ code using VisualStudio 2019.

I am using CMake to configure the project.

I need to use boost library which is compiled on my remote machine.

In console application, I can put the path of the include files I need when I go to the Properties of the project under Additional Include Directories field. And under Additional Include Directories I can put the path of boost library.

Now I can not find Properties when I right-click on my project to add what I need.

My boost include directory is under /home/ubuntu/boost_1_70_0

My boost libraries directory is under /home/ubuntu/boost_1_70_0/stage

How can add them in my CMake project?

Thank you!

EDIT:

This is my CMakelists.txt file:

# CMakeList.txt : CMake project for CMakeProject1, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

# Add source to this project's executable.
add_executable (CMakeProject1 "CMakeProject1.cpp" "CMakeProject1.h")


set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED OFF)  
set(Boost_USE_STATIC_RUNTIME OFF) 
find_package(Boost 1.70.0 REQUIRED COMPONENTS lambda) 

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    add_executable(CMakeProject1 CMakeProject1.cpp) 
    target_link_libraries(CMakeProject1 ${Boost_LIBRARIES})
endif()

# TODO: Add tests and install targets if needed.

And this is my .cpp file:

#include "CMakeProject1.h"
#include <iostream>
#include <iterator>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
using namespace std;

int main()
{
    typedef std::istream_iterator<int> in;

    std::cout << "Type in any number: ";

    std::for_each(
        in(std::cin), in(), std::cout
        << (boost::lambda::_1 * 10)
        << "\nType in another number: ");
}

The path of my boost directory is: /home/ubuntu/boost_1_70_0

The path of my boost libraries is: /home/ubuntu/boost_1_70_0/stage

When I run the .cpp file this CMake error occurs:

Error CMake Error at CMakeProject1/CMakeLists.txt:13 (find_package): Could not find a package configuration file provided by "Boost" (requested version 1.70.0) with any of the following names:

BoostConfig.cmake
boost-config.cmake

Add the installation prefix of "Boost" to CMAKE_PREFIX_PATH or set
"Boost_DIR" to a directory containing one of the above files. If "Boost" provides a separate development package or SDK, be sure it has been installed.

Kevin
  • 16,549
  • 8
  • 60
  • 74
Gonn
  • 377
  • 5
  • 21
  • [`INCLUDE_DIRECTORIES(path_to_include)`](https://cmake.org/cmake/help/v3.16/command/include_directories.html)? – ChrisMM Feb 10 '20 at 15:43
  • 1
    Does this answer your question? [How do you add Boost libraries in CMakeLists.txt?](https://stackoverflow.com/questions/6646405/how-do-you-add-boost-libraries-in-cmakelists-txt) – Kevin Feb 10 '20 at 15:46
  • You may also want to take a look at microsoft/vcpkg – Mizux Feb 11 '20 at 08:43
  • @squareskittles please can you see my problem edit – Gonn Feb 11 '20 at 09:15
  • @ChrisMM is boostconfig.cmake and boost-config.cmake what I am missing here ? I must download them ? – Gonn Feb 11 '20 at 09:27
  • I've never used boost; when you downloaded it, did it have those files? Do a search in the boost directory for them. If they already exist, then you just need to tell cmake where to find them. – ChrisMM Feb 11 '20 at 11:58

1 Answers1

0

CMake's find_package command has two modes: Module and Config mode. Many related questions on this site feature answers that are using Module mode. However, Boost 1.70 and greater provides a BoostConfig.cmake or boost-config.cmake package configuration file to easily use with find_package() Config mode. The package configuration file should be generated when you build Boost. For example, if you build Boost 1.72 into the stage directory, the BoostConfig.cmake file is located here:

boost_1_72_0/stage/lib/cmake/Boost-1.72.0/BoostConfig.cmake

Your error indicates that you are using Config mode, so you have two options:

Option 1

Do the steps recommended in the error message to help the Config mode package search complete successfully. Append the path to your Boost installation to the prefix path by adding this line to your CMake file before find_package():

list(APPEND CMAKE_PREFIX_PATH /home/ubuntu/boost_1_70_0)

Option 2

Force Module mode by setting the Boost_NO_BOOST_CMAKE variable before the call to find_package():

set(Boost_NO_BOOST_CMAKE ON)
Kevin
  • 16,549
  • 8
  • 60
  • 74
  • Please can you describe me the difference between the two modes of `find_package` command ? – Gonn Feb 11 '20 at 13:25
  • 1
    I added a link to the `find_package()` documentation in my post, which has lots of details. There are already questions about this topic on Stack Overflow, but [this answer](https://stackoverflow.com/a/20857070/3987854) describes the differences between **Module** and **Config** mode pretty well. – Kevin Feb 11 '20 at 13:32
  • Could you please see here https://stackoverflow.com/q/60297265/11587528 – Gonn Feb 19 '20 at 10:57