I am using boost-beast with Visual Studio 2019 on Windows. Everything was working until I added an existing class to main.cpp. Then one of the .h files could not open a boost file. I moved the #include statements into the .cpp files. It still fails with the same error.
The simplest code is:
#include <algorithm>
#include <iostream>
#include <boost/system/error_code.hpp>
#include "pml_webserver/pml_webserver.h"
#include "pml_webserver/product_factory.h"
#include "pml_webserver/config.h"
int main(int argc, char* argv[])
{
// omitted
}
All of the other files compiled. Main.cpp caused this error:
[4/12] Building CXX object CMakeFiles\pml_webserver.dir\src\main.cpp.obj
FAILED: CMakeFiles/pml_webserver.dir/src/main.cpp.obj
C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1421~1.277\bin\HostX64\x64\cl.exe /nologo /TP -IC:\Users\me\source\xplatform\core_pml_webserver\include -Iinclude /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /ZI /Ob0 /Od /RTC1 /JMC -std:c++17 /showIncludes /FoCMakeFiles\pml_webserver.dir\src\main.cpp.obj /FdCMakeFiles\pml_webserver.dir\ /FS -c C:\Users\me\source\xplatform\core_pml_webserver\src\main.cpp
C:\Users\me\source\xplatform\core_pml_webserver\include\pml_webserver\base_ws_handler.h(10): fatal error C1083: Cannot open include file: 'boost/system/error_code.hpp': No such file or directory
I cannot determine whether the problem is with Cmake, which I have little experience with, or whether it is caused by a namespace.
Edit: portions of CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(pml_webserver CXX)
find_package(Boost 1.70.0 REQUIRED COMPONENTS system date_time)
configure_file(include/pml_webserver/config.h.in
${CMAKE_BINARY_DIR}/include/pml_webserver/config.h
)
add_library(pml_webserver_lib
src/webserver.cpp
src/base_ws_handler.cpp
src/ws_handler_factory.cpp
src/product_ws_handler.cpp
src/product_factory.cpp
set_target_properties(pml_webserver_lib PROPERTIES PREFIX "")
target_include_directories(pml_webserver_lib PUBLIC ${CMAKE_SOURCE_DIR}/include PUBLIC ${CMAKE_BINARY_DIR}/include)
target_link_libraries(pml_webserver_lib
PRIVATE Boost::system
PRIVATE Boost::date_time
)
add_executable(pml_webserver src/main.cpp)
target_link_libraries(pml_webserver pml_webserver_lib)
I do not know where CMAKE_SOURCE_DIR
and CMAKE_BINARY_DIR
are defined.