ASIO Standalone with CMAKE compiling problem

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

My main.cpp

#include <iostream>
#include "include/asio-1.18.1/include/asio.hpp"

void print(const asio::error_code& /*e*/)
{
std::cout << "Hello, world!" << std::endl;
}

int main()
{
asio::io_context io;

asio::steady_timer t(io, asio::chrono::seconds(5));
t.async_wait(&print);

io.run();

return 0;
}

My Cmake

cmake_minimum_required(VERSION 3.17)
project(netDaemon)

set(CMAKE_CXX_STANDARD 14)

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.

N.B. The formatter doesn't work.
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"
Last edited on
Hi mbozzi,
Thanks for reply. For convenience i've modified the project structure like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.neDaemon
├── asio
│   ├── aclocal.m4
│   ├── compile
│   ├── config.guess
│   ├── config.sub
│   ├── configure
│   ├── configure.ac
│   ├── COPYING
│   ├── depcomp
│   ├── doc
│   ├── include
│   ├── INSTALL
│   ├── install-sh
│   ├── LICENSE_1_0.txt
│   ├── Makefile.am
│   ├── Makefile.in
│   ├── missing
│   ├── README
│   ├── src
│   └── test-driver
├── cmake-build-debug
├── CMakeCache.txt
├── CMakeFiles
│   ├── 3.16.3
│   ├── 3.17.3
│   ├── clion-environment.txt
│   ├── cmake.check_cache
│   ├── CMakeDirectoryInformation.cmake
│   ├── CMakeOutput.log
│   ├── CMakeTmp
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── netDaemon.dir
│   ├── Progress
│   ├── progress.marks
│   └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── main.cpp
└── netDaemon.cbp


Also have modified the cmake file :
1
2
3
4
5
6
7
8
9
10
11
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.
Topic archived. No new replies allowed.