Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get boost asio working #356

Open
cambp4 opened this issue May 25, 2022 · 5 comments
Open

can't get boost asio working #356

cambp4 opened this issue May 25, 2022 · 5 comments

Comments

@cambp4
Copy link

cambp4 commented May 25, 2022

Hi,

I'm trying to get boost asio working. I tried setting it up with the examples you gave. I tried with boost and with the asio standalone, none of which work.

It seems like cmake is downloading and putting things in my build folder, I can see folders related to boost or asio.

However when I compile a simple project that requires

#include <boost/asio.hpp>
// #include "asio.hpp"

I cannot compile it because it can't find boost asio.

this is my cmake

set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)


CPMAddPackage("gh:chriskohlhoff/asio#[email protected]")
if(asio_ADDED)
  add_library(asio INTERFACE)
  target_include_directories(asio SYSTEM INTERFACE ${asio_SOURCE_DIR}/asio/include)
  target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
  target_link_libraries(asio INTERFACE Threads::Threads)
endif()

add_library(FrameworkLibrary
        src/framework/event_manager/EventManager.cpp
        src/framework/event_manager/ControllerInterface.cpp
        src/framework/timer/TimerInterface.cpp
        src/framework/event_manager/SensorsActuatorsAndControllers.cpp
        src/framework/event_manager/EventDataStore.cpp
        src/framework/state_machine/State.cpp
        src/framework/logging/Logger.cpp
        src/framework/timer/Timer.cpp
        src/framework/event_manager/DelayTimer.cpp
        )
target_link_libraries(FrameworkLibrary
    PUBLIC
        Threads::Threads
        # Boost::asio
        asio
    )


@cambp4
Copy link
Author

cambp4 commented May 25, 2022

I managed to get boost asio working in the end, I had to add this in my cmake:

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
CPMAddPackage(
  NAME Boost
  VERSION 1.77.0
  GITHUB_REPOSITORY "boostorg/boost"
  GIT_TAG "boost-1.77.0"
)
if(Boost_ADDED)
    message("boost asio downloaded at " ${Boost_SOURCE_DIR}/libs/asio/include)

    file(GLOB files "${Boost_SOURCE_DIR}/libs/*/include")
    foreach(filename ${files})
        include_directories(${filename})
    endforeach()

    file(GLOB files "${Boost_SOURCE_DIR}/libs/*/*/include")
    foreach(filename ${files})
        include_directories(${filename})
    endforeach()
endif()

@OlivierLDff
Copy link
Contributor

OlivierLDff commented May 26, 2022

I've made this to use standalone asio: asio.cmake

set(ASIO_REPOSITORY
    "https://github.com/chriskohlhoff/asio"
    CACHE STRING "Repository of asio"
)
set(ASIO_TAG
    "asio-1-18-2"
    CACHE STRING "Git tag of asio"
)

set(ASIOCMAKE_REPOSITORY
    "https://github.com/OlivierLDff/asio.cmake"
    CACHE STRING "Repository of asio.cmake"
)
set(ASIOCMAKE_TAG
    "v1.1.1"
    CACHE STRING "Git tag of asio.cmake"
)

include(cmake/CPM.cmake)

CPMAddPackage(
  NAME asiocmake
  GIT_REPOSITORY ${ASIOCMAKE_REPOSITORY}
  GIT_TAG ${ASIOCMAKE_TAG}
  OPTIONS "ASIO_USE_CPM ON"
)

@ClausKlein
Copy link
Contributor

The fasted way I know to build boost is to use boost-cmake :

# ---- Add dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info

include(cmake/CPM.cmake)

# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")

if(EXISTS "$ENV{HOME}/.cache/CPM/boost_1_79_0")
  set(FETCHCONTENT_SOURCE_DIR_BOOST "$ENV{HOME}/.cache/CPM/boost_1_79_0" CACHE PATH "Boost source DIR")
endif()

CPMAddPackage(
  NAME boost-cmake GITHUB_REPOSITORY ClausKlein/boost-cmake
  GIT_TAG b7c741f42b089117221622c72783d2cb821843dc # feature/upgrade-to-boost-v1.79-0
)

target_link_libraries(
    tftpd PUBLIC Boost::filesystem Boost::boost
)
# ...

Note:

  • the Boost git repo takes to long to clone!
  • with the cmake based build, there is not longer Boost::asio lib in boost!
  • you habe to use the Boost::headers or Boost::boost interface lib
  • I extracted the Boost tar archive to $ENV{HOME}/.cache/CPM/boost_1_79_0 manually
bash-3.2$ make distclean
rm -rf ../.build-netkit-tftp-Debug .configure-Debug compile_commands.json *~ .*~ tags
find . -name '*~' -delete
bash-3.2$ time make
mkdir -p ../.build-netkit-tftp-Debug
cd ../.build-netkit-tftp-Debug && cmake -G Ninja -Wdeprecated -Wdev \
      -DUSE_LCOV=OFF -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_PREFIX_PATH="/usr/local;/usr/local;/usr" \
      -DCMAKE_STAGING_PREFIX=/usr/local \
      -DCMAKE_MODULE_PATH=/Users/clausklein/Workspace/cmake \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ /Users/clausklein/Workspace/cpp/netkit-tftp
-- use ccache
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/local/bin/git (found version "2.36.1") 
-- CPM: adding package [email protected] (v1.9.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/e3848b31ae54d78683c7e47eb420383f05024bdf)
-- The C compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Fetching Boost
-- Fetching Boost - done
-- Boost found: 1.79.0 /Users/clausklein/.cache/CPM/boost_1_79_0
-- Looking for __linux__
-- Looking for __linux__ - not found
-- Looking for _WIN32
-- Looking for _WIN32 - not found
-- Looking for __APPLE__
-- Looking for __APPLE__ - found
-- Looking for __ANDROID__
-- Looking for __ANDROID__ - not found
-- Looking for __FreeBSD__
-- Looking for __FreeBSD__ - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Found BZip2: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libbz2.tbd (found version "1.0.8") 
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found ZLIB: /usr/local/lib/libz.dylib (found version "1.2.11.1") 
-- Found the following ICU libraries:
--   uc (required)
--   dt (required)
--   i18n (required)
-- Failed to find all ICU components (missing: ICU_LIBRARY) (found version "70.1")
-- Found iconv library: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libiconv.tbd
-- CPM: adding package boost-cmake@0 (b7c741f42b089117221622c72783d2cb821843dc at /Users/clausklein/.cache/CPM/boost-cmake/7554d4bef168447f7af609d08f14400b5f978434)
-- CPM: adding package asio@0 (fea320c422a5de8d2c48cd02ae42e6251acf0030 at /Users/clausklein/.cache/CPM/asio/94e352fdf00c46cd2003e0c20605ad11b336d4ed)
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    USE_LCOV


-- Build files have been written to: /Users/clausklein/Workspace/cpp/.build-netkit-tftp-Debug
touch .configure-Debug
ln -sf /Users/clausklein/Workspace/cpp/netkit-tftp/../.build-netkit-tftp-Debug/compile_commands.json .
cmake --build ../.build-netkit-tftp-Debug
[17/20] Linking CXX static library lib/libboost_filesystem.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: lib/libboost_filesystem.a(windows_file_codecvt.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: lib/libboost_filesystem.a(windows_file_codecvt.o) has no symbols
[20/20] Linking CXX executable bin/tftpd_test

real	0m4.836s
user	0m2.103s
sys	0m1.825s
bash-3.2$ 

@Arniiiii
Copy link

#501 here's working example with boost

@ScottBailey
Copy link
Contributor

@cambp4 Is this still an issue? Do examples in the latest release correct the problem for you?

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

No branches or pull requests

5 participants