Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Standalone Asio not found - but asio.hpp is present #101

Open
galeone opened this issue Mar 26, 2018 · 4 comments
Open

Standalone Asio not found - but asio.hpp is present #101

galeone opened this issue Mar 26, 2018 · 4 comments

Comments

@galeone
Copy link

galeone commented Mar 26, 2018

Hi, thank you for this library!

I'm trying to use the library with ASIO but, although it's installed in my system, cmake fails.

My environment:
OS: Archlinux
compiler: clang
cmake version: 3.10.3

Steps to reproduce:

git clone https://github.com/eidheim/Simple-WebSocket-Server/
cd Simple-WebSocket-Server
mkdir build
cd build
cmake -DUSE_STANDALONE_ASIO=ON ..

Error: Standalone Asio not found

But ls /usr/include/asio* returns:

/usr/include/asio.hpp

/usr/include/asio:
associated_allocator.hpp     basic_socket.hpp              buffered_stream.hpp            defer.hpp                      handler_invoke_hook.hpp    is_write_buffered.hpp          serial_port_base.hpp         strand.hpp                 unyield.hpp
associated_executor.hpp      basic_socket_iostream.hpp     buffered_write_stream_fwd.hpp  detail                         handler_type.hpp           local                          serial_port.hpp              streambuf.hpp              use_future.hpp
async_result.hpp             basic_socket_streambuf.hpp    buffered_write_stream.hpp      dispatch.hpp                   high_resolution_timer.hpp  packaged_task.hpp              serial_port_service.hpp      stream_socket_service.hpp  uses_executor.hpp
basic_datagram_socket.hpp    basic_streambuf_fwd.hpp       buffer.hpp                     error_code.hpp                 impl                       placeholders.hpp               signal_set.hpp               system_context.hpp         version.hpp
basic_deadline_timer.hpp     basic_streambuf.hpp           buffers_iterator.hpp           error.hpp                      io_context.hpp             posix                          signal_set_service.hpp       system_error.hpp           waitable_timer_service.hpp
basic_io_object.hpp          basic_stream_socket.hpp       completion_condition.hpp       execution_context.hpp          io_context_strand.hpp      post.hpp                       socket_acceptor_service.hpp  system_executor.hpp        wait_traits.hpp
basic_raw_socket.hpp         basic_waitable_timer.hpp      connect.hpp                    executor.hpp                   io_service.hpp             raw_socket_service.hpp         socket_base.hpp              system_timer.hpp           windows
basic_seq_packet_socket.hpp  bind_executor.hpp             coroutine.hpp                  executor_work_guard.hpp        io_service_strand.hpp      read_at.hpp                    spawn.hpp                    thread.hpp                 write_at.hpp
basic_serial_port.hpp        buffered_read_stream_fwd.hpp  datagram_socket_service.hpp    generic                        ip                         read.hpp                       ssl                          thread_pool.hpp            write.hpp
basic_signal_set.hpp         buffered_read_stream.hpp      deadline_timer.hpp             handler_alloc_hook.hpp         is_executor.hpp            read_until.hpp                 ssl.hpp                      time_traits.hpp            yield.hpp
basic_socket_acceptor.hpp    buffered_stream_fwd.hpp       deadline_timer_service.hpp     handler_continuation_hook.hpp  is_read_buffered.hpp       seq_packet_socket_service.hpp  steady_timer.hpp             ts

Hence asio.hpp is present and the whole asio library too.

How can I fix this? (My guess is that the problem is related to cmake somehow)

Thank you

@galeone
Copy link
Author

galeone commented Mar 26, 2018

The problem is in pthread linking, it looks like your CMake file (when using CHECK_INCLUDE_FILE_CXX(asio.hpp)) does not link against pthread

Determining if the include file asio.hpp exists failed with the following output:
Change Dir: /tmp/Simple-WebSocket-Server/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_1b98a/fast"
/usr/bin/make -f CMakeFiles/cmTC_1b98a.dir/build.make CMakeFiles/cmTC_1b98a.dir/build
make[1]: Entering directory '/tmp/Simple-WebSocket-Server/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_1b98a.dir/CheckIncludeFile.cxx.o
/usr/bin/c++     -o CMakeFiles/cmTC_1b98a.dir/CheckIncludeFile.cxx.o -c /tmp/Simple-WebSocket-Server/build/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx
Linking CXX executable cmTC_1b98a
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1b98a.dir/link.txt --verbose=1
/usr/bin/c++       -rdynamic CMakeFiles/cmTC_1b98a.dir/CheckIncludeFile.cxx.o  -o cmTC_1b98a 
CMakeFiles/cmTC_1b98a.dir/CheckIncludeFile.cxx.o: In function `asio::detail::posix_thread::~posix_thread()':
CheckIncludeFile.cxx:(.text._ZN4asio6detail12posix_threadD2Ev[_ZN4asio6detail12posix_threadD5Ev]+0x26): undefined reference to `pthread_detach'
CMakeFiles/cmTC_1b98a.dir/CheckIncludeFile.cxx.o: In function `asio::detail::posix_thread::join()':
CheckIncludeFile.cxx:(.text._ZN4asio6detail12posix_thread4joinEv[_ZN4asio6detail12posix_thread4joinEv]+0x2b): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_1b98a.dir/build.make:98: cmTC_1b98a] Error 1
make[1]: Leaving directory '/tmp/Simple-WebSocket-Server/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_1b98a/fast] Error 2

@eidheim
Copy link
Owner

eidheim commented Mar 29, 2018

pthread linking should be added here: https://github.com/eidheim/Simple-WebSocket-Server/blob/master/CMakeLists.txt#L19 if needed.

@eidheim
Copy link
Owner

eidheim commented Mar 29, 2018

This seems to be a problem with cmake's CheckIncludeFileCXX though. I just confirmed this issue on Antergos. Temporary workaround:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b0ea16..8f31cb5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,11 +22,6 @@ target_link_libraries(simple-websocket-server INTERFACE ${CMAKE_THREAD_LIBS_INIT
 # Remove Boost system, thread, regex components; use Boost::<component> aliases; remove Boost target_include_directories
 if(USE_STANDALONE_ASIO)
     target_compile_definitions(simple-websocket-server INTERFACE USE_STANDALONE_ASIO)
-    include(CheckIncludeFileCXX)
-    CHECK_INCLUDE_FILE_CXX(asio.hpp HAVE_ASIO)
-    if(NOT HAVE_ASIO)
-        message(FATAL_ERROR "Standalone Asio not found")
-    endif()
 else()
     find_package(Boost 1.54.0 COMPONENTS system thread coroutine context REQUIRED)
     target_link_libraries(simple-websocket-server INTERFACE ${Boost_LIBRARIES})

@galeone
Copy link
Author

galeone commented Mar 29, 2018

Yeah, I ended up with the same workaround (although it should be temporary for sure since we're not checking if asio.hpp is present hence the compilation can start and fail if the library is not present for real).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants