Linking boost library with Boost_USE_STATIC_LIB OFF on Windows - c++

My CMakeFiles.txt looks like this:
cmake_minimum_required ( VERSION 2.6 )
# Set warnings on and enable debugging
SET( CMAKE_C_FLAGS "-Wall -q" )
include(FindBoost)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
if( Boost_FOUND )
message( STATUS "Boost found!" )
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
# Needed for asio
if(WIN32)
target_link_libraries(foo wsock32 ws2_32)
endif()
target_link_libraries(foo ${Boost_LIBRARIES})
endif()
I render the project for Visual Studio 2013 64-bit:
cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:\Development\Tools\boost_1_57_0\stage\x64\lib ..\KServer
The output is:
-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013 Win64
-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.57.0
-- Boost version: 1.57.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- Boost found!
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Development/Private/C++/KServerProject
This is all good and well.
Problem starts here:
When I change my cmake file to use:
set(Boost_USE_STATIC_LIBS OFF)
I then get the following error in Visual Studio when building:
error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib' D:\Development\Private\C++\KServerProject\src\LINK foo
Checking the Property Pages in the studio the library is added as a dependency:
When manually adding the folder D:\Development\Tools\boost_1_57_0\stage\x64\lib to Additional Library Directories it builds fine.
How can I get it to create project using dynamic libs?

I believe you need to add
add_definitions( -DBOOST_ALL_NO_LIB )
See http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html. I have it set in my CMakeLists.txt and it works for my visual studio builds with boost. As a test, I removed it and got the same error you did.
For what it is worth, here is how I use boost with cmake.
# boost
set(Boost_NO_SYSTEM_PATHS true)
set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost")
set (Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED
COMPONENTS
system program_options thread filesystem
date_time chrono timer regex serialization
)
include_directories(${Boost_INCLUDE_DIRS})
link_libraries(${Boost_LIBRARIES})
if (WIN32)
# disable autolinking in boost
add_definitions( -DBOOST_ALL_NO_LIB )
# force all boost libraries to dynamic link (we already disabled
# autolinking, so I don't know why we need this, but we do!)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()

Related

cmake error for header-only library: `include could not find load file`

I've been trying to change a makefile c++ project into a cmake project, and I've been having som difficulty. cmake seems to be looking for stuff in /usr/local/lib/ instead of /usr/local/include/ and I'm not sure why that is.
This library is header-only, and so I've been following this tutorial My header-only library in include seems to "build" fine, but I keep getting the following error when I try to generate a makefile to build my example program:
me:~/pf/examples/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/lib/cmake/pf/pfConfig.cmake:27 (include):
include could not find load file:
/usr/local/lib/cmake/pf/pf_exampleTargets.cmake
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
examples/CMakeLists.txt creates another fresh project:
project(pf_example)
cmake_minimum_required (VERSION 3.12)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 17)
# "install" pf
find_package(pf CONFIG REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp})
message("${SOURCES}")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} pf::pf)
The root directory CMakeLists.txt file is more complicated. It's the one that was adapted from the tutorial I mentioned above:
cmake_minimum_required(VERSION 3.12)
project("pf" VERSION 1.0.1
DESCRIPTION "A header only c++ template library for fast particle filtering."
HOMEPAGE_URL "https://github.com/tbrown122387/pf")
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include)
To install this header only library, before I try to build the examples project, I typed the following commands into the command line:
cd ~/pf
mkdir build
cd build/
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/include
sudo cmake --build . --config Release --target install -- -j $(nproc)
I didn't post it, but there's also a file cmake/pfconfig.cmake.in that is verbatim copied from the tutorial above.
Your install prefix is specified as /usr/local/include so the files would be installed as:
headers into /usr/local/include/include
libraries into /usr/local/include/libs
cmake stuff into /usr/local/include/share/${PROJECT_NAME}/cmake
Those paths are just wrong. Just set CMAKE_INSTALL_PREFIX=/usr/local (ie. remove include) and install it inside /usr/local/ tree.
A few took care of this issue.
in CMakeLists.txt change install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include) to install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/pf DESTINATION include) so the files don't clutter up the installation locations. This also requires creating pf/include/pf and moving all the files in pf/include to pf/include/pf.
Follow advice in #KamilCuk's answer.
In examples/CMakeLists.txt change file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp}) to file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/*.h ${CMAKE_SOURCE_DIR}/*.cpp)
Also note that my /usr/local/lib and /usr/local/include were quite cluttered up due to my numerous earlier failed attempts, so I deleted a bunch of files in there and re-installed fresh.

libtins compile with arm-linux-gnueabi-g++ cmake error

im facing a problem with cmake when trying to compile libtins library to embedded device using arm-linux-gnueabi-g++
i must say that when im compiling the library for linux (not embedded) the cmake works fine! and no error is shown! like in this toturial: compiling libtins with linux
but i need the cross compiler option so i did these steps:
first i installed the arm cross compiler with the apt get command, second, i downloaded the libtins master directory from the official github and i created a build dir and used the cmake command in the libtins cross compile toturial here :
libtins cross compile
i change it a bit so i can use my own arm compiler and the command is:
cmake ../ -DCMAKE_FIND_ROOT_PATH=/usr/lib/ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabi-g++ -DLIBTINS_ENABLE_WPA2=0 -DCROSS_COMPILING=1
and i get this error in the terminal:
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- Build will generate a shared library. Use LIBTINS_BUILD_SHARED=0 to perform a static build
CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find PCAP (missing: PCAP_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindPCAP.cmake:46 (find_package_handle_standard_args)
CMakeLists.txt:61 (FIND_PACKAGE)
but i did a lot of resarch in the web and added this line -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu to the cmake command so i run this command in the terminal :
cmake ../ -DCMAKE_FIND_ROOT_PATH=/usr/lib/ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabi-g++ -DLIBTINS_ENABLE_WPA2=0 -DCROSS_COMPILING=1 -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu
and it seems to find pcap but now i get another error:
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- Build will generate a shared library. Use LIBTINS_BUILD_SHARED=0 to perform a static build
-- Found PCAP: /usr/lib/x86_64-linux-gnu/libpcap.so
-- Performing Test PCAP_LINKS_SOLO
-- Performing Test PCAP_LINKS_SOLO - Failed
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test PCAP_NEEDS_THREADS
-- Performing Test PCAP_NEEDS_THREADS - Failed
CMake Error at cmake/Modules/FindPCAP.cmake:70 (message):
Couldn't determine how to link against libpcap
Call Stack (most recent call first):
CMakeLists.txt:61 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/root/Desktop/libtins-master/build/CMakeFiles/CMakeOutput.log".
See also "/root/Desktop/libtins-master/build/CMakeFiles/CMakeError.log".
my cmakeLists file looks like this:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
PROJECT(libtins)
OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON)
OPTION(LIBTINS_BUILD_TESTS "Build tests" ON)
# Compile in release mode by default
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ELSE(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.")
ENDIF(NOT CMAKE_BUILD_TYPE)
# Compilation flags.
IF(MSVC)
# Don't always use Wall, since VC's /Wall is ridiculously verbose.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
# Disable VC secure checks, since these are not really issues.
ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-DNOGDI=1")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
ENDIF()
IF(APPLE)
# This is set to ON as of policy CMP0042
SET(CMAKE_MACOSX_RPATH ON)
ENDIF()
# Build output checks
OPTION(LIBTINS_BUILD_SHARED "Build libtins as a shared library." ON)
IF(LIBTINS_BUILD_SHARED)
MESSAGE(
STATUS
"Build will generate a shared library. "
"Use LIBTINS_BUILD_SHARED=0 to perform a static build"
)
SET(LIBTINS_TYPE SHARED)
ELSE(LIBTINS_BUILD_SHARED)
MESSAGE(STATUS "Build will generate a static library.")
SET(LIBTINS_TYPE STATIC)
ADD_DEFINITIONS("-DTINS_STATIC=1")
ENDIF(LIBTINS_BUILD_SHARED)
# The version number.
SET(TINS_VERSION_MAJOR 4)
SET(TINS_VERSION_MINOR 3)
SET(TINS_VERSION_PATCH 0)
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
# Required Packages
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
# Allow disabling packet capture mechanism
OPTION(LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON)
# Look for libpcap
IF(LIBTINS_ENABLE_PCAP)
FIND_PACKAGE(PCAP REQUIRED)
SET(TINS_HAVE_PCAP ON)
ENDIF()
# Set some Windows specific flags
IF(WIN32)
# We need to link against these libs
SET(LIBTINS_OS_LIBS Ws2_32.lib Iphlpapi.lib)
# Add the NOMINMAX macro to avoid Windows' min and max macros.
ADD_DEFINITIONS(-DNOMINMAX)
# MinWG need some extra definitions to compile properly (WIN32 for PCAP and WIN32_WINNT version for ws2tcpip.h)
IF(MINGW)
ADD_DEFINITIONS(-DWIN32)
MACRO(get_WIN32_WINNT version)
IF (WIN32 AND CMAKE_SYSTEM_VERSION)
SET(ver ${CMAKE_SYSTEM_VERSION})
STRING(REPLACE "." "" ver ${ver})
STRING(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
SET(${version} "0x${ver}")
ENDIF()
ENDMACRO()
get_WIN32_WINNT(ver)
ADD_DEFINITIONS(-D_WIN32_WINNT=${ver})
ENDIF(MINGW)
ENDIF(WIN32)
INCLUDE(ExternalProject)
# *******************
# Compilation options
# *******************
# Always check for C++ features
INCLUDE(CheckCXXFeatures)
IF(HAS_GCC_BUILTIN_SWAP)
SET(TINS_HAVE_GCC_BUILTIN_SWAP ON)
ENDIF()
# C++11 support
OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" ON)
IF(LIBTINS_ENABLE_CXX11)
# We only use declval and decltype on gcc/clang as VC fails to build that code,
# at least on VC2013
IF(HAS_CXX11_RVALUE_REFERENCES AND HAS_CXX11_FUNCTIONAL AND HAS_CXX11_CHRONO AND
HAS_CXX11_NOEXCEPT AND ((HAS_CXX11_DECLVAL AND HAS_CXX11_DECLTYPE) OR MSVC))
SET(TINS_HAVE_CXX11 ON)
MESSAGE(STATUS "Enabling C++11 features")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
ELSE()
MESSAGE(WARNING "The compiler doesn't support the necessary C++11 features. "
"Disabling C++11 on this build")
ENDIF()
ELSE(LIBTINS_ENABLE_CXX11)
MESSAGE(
WARNING
"Disabling C++11 features. Use LIBTINS_ENABLE_CXX11=1 to enable them. "
"Unless you are using an old compiler, you should enable this option, "
"as it increases the library's performance")
ENDIF(LIBTINS_ENABLE_CXX11)
# IEEE 802.11 and WPA2 decryption support
OPTION(LIBTINS_ENABLE_DOT11 "Compile libtins with IEEE 802.11 support" ON)
OPTION(LIBTINS_ENABLE_WPA2 "Compile libtins with WPA2 decryption features (requires OpenSSL)" ON)
IF(LIBTINS_ENABLE_DOT11)
SET(TINS_HAVE_DOT11 ON)
MESSAGE(STATUS "Enabling IEEE 802.11 support.")
IF(LIBTINS_ENABLE_WPA2)
FIND_PACKAGE(OpenSSL)
IF(OPENSSL_FOUND)
SET(TINS_HAVE_WPA2_DECRYPTION ON)
MESSAGE(STATUS "Enabling WPA2 decryption support.")
ELSE()
MESSAGE(WARNING "Disabling WPA2 decryption support since OpenSSL was not found")
# Default this to empty strings
SET(OPENSSL_INCLUDE_DIR "")
SET(OPENSSL_LIBRARIES "")
ENDIF()
ELSE(LIBTINS_ENABLE_WPA2)
MESSAGE(STATUS "Disabling WPA2 decryption support.")
ENDIF(LIBTINS_ENABLE_WPA2)
ENDIF(LIBTINS_ENABLE_DOT11)
# Optionally enable TCPIP classes (on by default)
OPTION(LIBTINS_ENABLE_TCPIP "Enable TCPIP classes" ON)
IF(LIBTINS_ENABLE_TCPIP AND TINS_HAVE_CXX11)
SET(TINS_HAVE_TCPIP ON)
MESSAGE(STATUS "Enabling TCPIP classes")
ELSE()
SET(TINS_HAVE_TCPIP OFF)
MESSAGE(STATUS "Disabling TCPIP classes")
ENDIF()
# Search for libboost
FIND_PACKAGE(Boost)
# Optionally enable the ACK tracker (on by default)
OPTION(LIBTINS_ENABLE_ACK_TRACKER "Enable TCP ACK tracking support" ON)
IF(LIBTINS_ENABLE_ACK_TRACKER AND TINS_HAVE_CXX11)
IF (Boost_FOUND)
MESSAGE(STATUS "Enabling TCP ACK tracking support.")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
SET(TINS_HAVE_ACK_TRACKER ON)
ELSE()
MESSAGE(WARNING "Disabling ACK tracking support as boost.icl was not found")
SET(TINS_HAVE_ACK_TRACKER OFF)
ENDIF()
ELSE()
SET(TINS_HAVE_ACK_TRACKER OFF)
MESSAGE(STATUS "Disabling ACK tracking support")
ENDIF()
# Optionally enable the TCP stream custom data (on by default)
OPTION(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA "Enable TCP stream custom data support" ON)
IF(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA AND TINS_HAVE_CXX11)
IF (Boost_FOUND)
MESSAGE(STATUS "Enabling TCP stream custom data support.")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA ON)
ELSE()
MESSAGE(WARNING "Disabling TCP stream custom data support as boost.any was not found")
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
ENDIF()
ELSE()
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
MESSAGE(STATUS "Disabling TCP stream custom data support")
ENDIF()
OPTION(LIBTINS_ENABLE_WPA2_CALLBACKS "Enable WPA2 callback interface" ON)
IF(LIBTINS_ENABLE_WPA2_CALLBACKS AND TINS_HAVE_WPA2_DECRYPTION AND TINS_HAVE_CXX11)
SET(STATUS "Enabling WPA2 callback interface")
SET(TINS_HAVE_WPA2_CALLBACKS ON)
ENDIF()
# Use pcap_sendpacket to send l2 packets rather than raw sockets
IF(WIN32)
SET(USE_PCAP_SENDPACKET_DEFAULT ON)
ELSE(WIN32)
SET(USE_PCAP_SENDPACKET_DEFAULT OFF)
ENDIF(WIN32)
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
${USE_PCAP_SENDPACKET_DEFAULT})
IF(LIBTINS_ENABLE_PCAP AND LIBTINS_USE_PCAP_SENDPACKET)
SET(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
ENDIF()
# Add a target to generate API documentation using Doxygen
FIND_PACKAGE(Doxygen QUIET)
IF(DOXYGEN_FOUND)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
#ONLY
)
ADD_CUSTOM_TARGET(
docs
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
ENDIF(DOXYGEN_FOUND)
# Configuration file
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/include/tins/config.h.in"
"${PROJECT_SOURCE_DIR}/include/tins/config.h"
)
IF (NOT CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib)
ENDIF()
IF (NOT CMAKE_INSTALL_BINDIR)
SET(CMAKE_INSTALL_BINDIR bin)
ENDIF()
# The library output directory
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
# Support for pkg-config
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
SET(pkgconfig_version ${LIBTINS_VERSION})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libtins.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libtins.pc #ONLY)
INSTALL(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libtins.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
# Confiugure the uninstall script
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE #ONLY
)
# Add uninstall target
ADD_CUSTOM_TARGET(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# ******************
# Add subdirectories
# ******************
ADD_SUBDIRECTORY(src)
IF(LIBTINS_BUILD_EXAMPLES)
IF(LIBTINS_ENABLE_PCAP)
ADD_SUBDIRECTORY(examples)
ELSE()
MESSAGE(STATUS "Not building examples as pcap support is disabled")
ENDIF()
ENDIF()
IF(LIBTINS_BUILD_TESTS)
# Only include googletest if the git submodule has been fetched
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
# Enable tests and add the test directory
MESSAGE(STATUS "Tests have been enabled")
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
ExternalProject_Add(
googletest
DOWNLOAD_COMMAND ""
SOURCE_DIR ${GOOGLETEST_ROOT}
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
"-Dgtest_force_shared_crt:bool=ON"
"-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER}"
INSTALL_COMMAND ""
)
# Make sure we build googletest before anything else
ADD_DEPENDENCIES(tins googletest)
ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)
ELSE()
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
ENDIF()
ENDIF()
# **********************************
# CMake project configuration export
# **********************************
if(UNIX)
set(CONF_CMAKE_INSTALL_DIR lib/cmake/libtins)
else()
set(CONF_CMAKE_INSTALL_DIR CMake)
endif()
# Add all targets to the build-tree export set
EXPORT(
TARGETS tins
FILE "${PROJECT_BINARY_DIR}/libtinsTargets.cmake"
)
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
EXPORT(PACKAGE libtins)
# Create the libtinsConfig.cmake and libtinsConfigVersion.cmake files
# for the build tree
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
CONFIGURE_FILE(
cmake/libtinsConfig.cmake.in
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake" #ONLY
)
CONFIGURE_FILE(
cmake/libtinsConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake" #ONLY
)
# Install the libtinsConfig.cmake and libtinsConfigVersion.cmake
INSTALL(
FILES
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake"
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
COMPONENT dev
)
# Install the export set for use with the install-tree
INSTALL(
EXPORT libtinsTargets
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
COMPONENT dev
)
i didnt touch it and im sure that the solution needs to be in this file and im a little lost with cmake files so any help will be great!

Torch CMake Error at CMakeLists.txt:10 (find_package) in C++

I am trying to create a Eclipse C++ project by CMake which calls torch/torch.h . I run cmake -G "Eclipse CDT4 - Unix Makefiles" ./ to create a Eclipse project, but I get this error:
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
Could not find a package configuration file provided by "Torch" with any of
the following names:
TorchConfig.cmake
torch-config.cmake
Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
"Torch_DIR" to a directory containing one of the above files. If "Torch"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
In which CMakeLists.txt is located in the current directory that has:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)
find_package(Torch REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test "${TORCH_LIBRARIES}")
set_property(TARGET test PROPERTY CXX_STANDARD 11)
Apparently, it cannot find TorchConfig.cmake and torch-config.cmake files; although, I have TorchConfig.cmake in /home/afshin/libtorch/share/cmake/Torch. I added the corresponding path into the CMakeLists.txt file by testing each of:
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake/Torch;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch;${CMAKE_MODULE_PATH}")
set(Torch_DIR "/home/afshin/libtorch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake/Torch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake;${Torch_DIR}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake/Torch;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch;${DCMAKE_PREFIX_PATH}")
But, it did not help and I still get same error.
I appreciate any help or comments.
I also tried the cmake-gui and I get same error:
Thanks,
Afshin
I was able to solve the problem by editing the CMakeLists.txt as:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test_cmake)
set(CMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake/Torch")
find_package(Torch REQUIRED)
add_executable(test_cmake ./src/test_cmake.cpp)
target_link_libraries(test_cmake "${TORCH_LIBRARIES}")
set_property(TARGET test_cmake PROPERTY CXX_STANDARD 11)
Alternatively, using the cmake-gui also I was able to solve the problem by the following setting:
by hitting configure, and then generate.
Finally, I imported this project into Eclipse by selecting Makefile Project With Existing Code. This code is compiled and built successfully.
The following modified CMakeLists.txt file works without the apparently missing TorchConfig.cmake (also missing in the vcpkg installation here). I recommend Microsoft's vcpkg for cross-platform packages (c++ libraries) management (usage here). But the code is vcpkg independent: one can set TORCH_BASE_PATH (or Torch_INCLUDE_DIR and Torch_LIBRARIES) to the proper paths.
#[[
tested with:
- CMake 3.13
- Visual Studio Community Edition 15.9.4
(CMake generator: "Visual Studio 15 2017 Win64")
- torch-th library installed with vcpkg
generic: vcpkg install torch-th
for macOS: vcpkg install torch-th:x64-osx-dynamic
x64-osx-dynamic triplet must be created: x64-osx + "set(VCPKG_LIBRARY_LINKAGE dynamic)"
for Windows: vcpkg install torch-th:x64-windows
- easy torch sample: https://apaszke.github.io/torch-internals.html
]]
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)
# cannot work without a "package configuration file" (TorchConfig.cmake)
# so we replace it with find_path and find_library
#find_package(Torch REQUIRED)
#[[
the environement variable VCPKG_ROOT used here, contains the path to vcpkg installation folder
replace the two paths with your paths to TH installation
usage: #include "TH/TH.h"
]]
set(TORCH_BASE_PATH "$ENV{VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}")
message(STATUS TORCH_BASE_PATH=${TORCH_BASE_PATH})
set(Torch_INCLUDE_DIR "${TORCH_BASE_PATH}/include")
set(Torch_LIBRARIES "${TORCH_BASE_PATH}/lib")
# target_link_libraries is to be preferred
#link_directories(${Torch_LIBRARIES})
find_library(LIBRARY_TORCH TH HINTS ${Torch_LIBRARIES})
#[[
even simpler
if you use the vcpkg toolchain file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
find_path(Torch_INCLUDE_DIR TH/TH.h)
find_library(LIBRARY_TORCH TH)
]]
add_executable(test test.cpp)
target_include_directories(test PRIVATE ${Torch_INCLUDE_DIR})
target_link_libraries(test ${LIBRARY_TORCH})
set(CMAKE_CXX_STANDARD 11)
#set_property(TARGET test PROPERTY CXX_STANDARD 11)

CMake cannot find requested Boost libraries

Now that I've looked through other peoples solutions for several hours and could not find quite the right answer for my problem I would like to bring my specific problem to you. :)
I am trying to build vsomeip with CMake. For that I previously built boost 1.55, however, I get the following errors in CMake:
The C compiler identification is MSVC 19.0.24215.1
The CXX compiler identification is MSVC 19.0.24215.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visua Studio 14.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Setting build type to 'RelWithDebInfo' as none was specified.
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindBoost.cmake:2025 (message):
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: C:/Program Files/boost/boost_1_55_0
Could not find the following static Boost libraries:
boost_system
boost_thread
boost_log
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:99 (find_package)
Boost was not found!
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Systemd was not found, watchdog disabled!
using MSVC Compiler
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x00
Predefined routing application: vsomeipd
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
CMake Warning at CMakeLists.txt:335 (message):
Doxygen is not installed. Documentation can not be built.
CMake Warning at CMakeLists.txt:374 (message):
asciidoc is not installed. Readme can not be built.
GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
Configuring incomplete, errors occurred!
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles /CMakeOutput.log".
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles/CMakeError.log".
It cannot find the static Boost libraries. Now, I've tried playing around with the CMakeList.txt and here is the part of it that would be supposed to handle the linking:
# Boost
set(BOOST_INCLUDE_DIR C:/Program Files/Boost/boost_1_55_0)
set(BOOST_LIBRARYDIR C:/Program Files/Boost/boost_1_55_0/stage/libs)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
if(Boost_FOUND)
if(Boost_LIBRARY_DIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR not empty using it: ${Boost_LIBRARY_DIR}" )
else()
if(BOOST_LIBRARYDIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR empty but BOOST_LIBRARYDIR is set setting Boost_LIBRARY_DIR to: ${BOOST_LIBRARYDIR}" )
set(Boost_LIBRARY_DIR ${BOOST_LIBRARYDIR})
endif()
endif()
else()
MESSAGE( STATUS "Boost was not found!")
endif()
I have also tried using a newer boost version (1.67) with same results. Any help will be dearly appreciated!
Check if your compiled libraries are in the following directory:
C:/Program Files/Boost/boost_1_55_0/stage/libs
If not, set your lib folder directory path:
set(BOOST_LIBRARYDIR path_to_lib_directory)
As #Tsyvarev suggested I used set(Boost_DEBUG ON) to trace the exact locations and files that CMake was looking for and the discovered several problems:
1.) Setting the path to "C:/Program Files/Boost/boost_1_55_0"
causes problems, because of the space in the path
2.) It searched for the libraries covering multiple formats like: boost_thread-vc141-mt-gd-x32-1_55.lib.
However, when I built boost with incorrect parameters, so my libs were built like this:
libboost_thread-vc-mt-1_55.lib, which is not of the correct format.
3.) Unfortunately adding other options when building boost, e.g.:
b2 toolset=msvc-14.1 address-model=32 --build-type=complete
caused other errors. Also building boost_1_67_0 manually worked for me at all.
My solution to the problem was to simply take one of the third-party download( https://dl.bintray.com/boostorg/release/1.67.0/binaries/). This way all the libraries were built correctly and I had no trouble linking to them.

Compiling an OpenCV project using CMake on Cygwin, with OpenCV installed for Windows

Situation:
I have a Windows 7 machine with OpenCV for Windows installed on it.
My OpenCV C++ projects work fine with Visual Studio 2010.
I want to run my existing OpenCV C++ projects to run on Raspberry Pi and on other Linux machines.
Trouble
As a first step, I am trying to compile my .cpp & .h files using GCC on Cygwin on my Windows Machine. For this purpose I am trying to use CMake package for Cygwin, but CMake gives error that it cannot find OpenCV package. (error is listed below).
Question:
Do i need to install OpenCV package for Cygwin separately for CMake to work ?
Is there a way to using my existing OpenCV for Win to work with CMake ?
What environment variables need to be set ?
(Currently only a variable OPENCV_DIR is set to C:/opencv/build)
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
PROJECT (testProj)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
src/imgProcess.cpp
)
set( NAME_HEADERS
include/imgProcess.h
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( testProj ${NAME_SRC} ${NAME_HEADERS} )
target_link_libraries( test ${OpenCV_LIBS} )
cmake error
$ cmake .
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/Work/Project/cmaketest/CMakeFiles/CMakeOutput.log".
The variable should be called OpenCV_DIR, it must have the same capitalization as in find_package(OpenCV REQUIRED).
As #berak, stated in the comment, I installed OpenCV Package for Cygwin using Cygwin Ports. (Without any src or requiring any build, simple install only).
Had to tweak my CMakeLists.txt a little but it compiled well.
##### CMakeLists.txt ########
cmake_minimum_required(VERSION 2.8.4)
PROJECT (test)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
src/mytest.cpp
)
set( NAME_HEADERS
include/mytest.hpp
)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( test ${NAME_SRC} ${NAME_HEADERS} )
include_directories(/usr/include /usr/include/opencv2 /usr/include/opencv ${CMAKE_CURRENT_SOURCE_DIR}/include)
link_directories(/usr/lib ${CMAKE_BINARY_DIR}/bin)
target_link_libraries(test opencv_core opencv_highgui opencv_imgproc)
(Now, I have totally different trouble of runtime error : Gtk-WARNING **: cannot open display, but its another story of not having XServer on Cygwin)
First take the following steps to build opencv using visual studio and cmake gui.
Clone into the opencv source code repo
$ git clone https://github.com/Itseez/opencv.git
Navigate inside the folder and checkout to the specified version
$ git checkout 3.0.0
Create a build directory and build opencv in there using CMake and visual studio. Note that by default opencv will build dynamic libraries unless you enable the option of building opencv static libraries.
Once done you should handle the environment variables. Create a variable named OpenCV_DIR and point it to the build directory of opencv. Then update your PATH variable to have new opencv dll files added. Usually they can be found in the directory opencv\build\bin\Release assuming you have built opencv in Release mode
Then set up your project CMakeList.txt as follows
find_package(OpenCV REQUIRED)
include_directories(
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(test
${OpenCV_LIBS}
)
The command find_package(OpenCV REQUIRED) finds the opencv configuration files in the directory "opencv/build", aka the directory in which you have built opencv (That's why you should set the value of the variable ${OpenCV_DIR} to this directory so the command find_package can find the required files in there).
The two variables {OpenCV_INCLUDE_DIRS} and ${OpenCV_LIBS} have already been set in those configuration files. So you should be all set.