Hi All, and happy new year!
I'm new with asio, and i've a problem to compile example with ASIO STANDALONE.
The project directory structure:
├── cmake-build-debug
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── include
│ ├── Makefile
│ └── netDaemon.cbp
├── CMakeLists.txt
├── include
│ └── asio-1.18.1
└── main.cpp
add_library(asio INTERFACE)
target_compile_options(asio INTERFACE ASIO_STANDALONE)
target_include_directories(asio INTERFACE /include/asio-1.18.1/include)
target_link_libraries(asio INTERFACE pthread) # Using ASIO requires you link your final executable/library with your system's threading library (e.g. pthread on linux)
add_executable(netDaemon main.cpp)
Output error:
in file included from /home/ciclonite/CLionProjects/netDaemon/include/asio-1.18.1/include/asio.hpp:18,
from /home/ciclonite/CLionProjects/netDaemon/main.cpp:3:
/home/ciclonite/CLionProjects/netDaemon/include/asio-1.18.1/include/asio/associated_allocator.hpp:18:10: fatal error: asio/detail/config.hpp: No such file or directory
18 | #include "asio/detail/config.hpp"
| ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I'm unable to find the problem. Any help is appreciated.
Your build script contains target_include_directories(asio INTERFACE /include/asio-1.18.1/include)
This is an absolute path. Did you mean target_include_directories(asio INTERFACE "${CMAKE_SOURCE_DIR}/include/asio-1.18.1/include")
instead?
If the include directories are properly set, you should be able to say #include "asio.hpp"
cmake_minimum_required(VERSION 3.16)
project(netDaemon)
set(CMAKE_CXX_STANDARD 17)
add_library(asio INTERFACE)
target_compile_options(asio INTERFACE ASIO_STANDALONE)
target_include_directories(asio INTERFACE ${CMAKE_SOURCE_DIR}/asio/include)
message("CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/asio/include")
target_link_libraries(asio INTERFACE pthread) # Using ASIO requires you link your final executable/library with your system's threading library (e.g. pthread on linux)
add_executable(netDaemon main.cpp)
Now the path, thanks to your suggestion it's correct, but when i try to include "asio.hpp" i'm unable to compile -> fatal error: asio.hpp: No such file or directory
If i pass the full path have the same error as above : atal error: asio/detail/config.hpp: No such file or directory
Thanks for your patience.