I've previous boost installation from ubuntu repo which is 1.42 and its installed in /usr/lib Now I downloaded 1.52 and ./b2 install that installed it in /usr/local/lib. now cmake is detecting 1.52 only and using include Path from /usr/local/include (which is 1.52) and using library directory /usr/lib (which is 1.42) and giving undefined reference errors.
cmake_minimum_required(VERSION 2.6)
PROJECT(app)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.52 COMPONENTS filesystem program_options thread system serialization REQUIRED)
ADD_EXECUTABLE(app list_of_cpp_files)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")
TARGET_LINK_LIBRARIES(app ${Boost_LIBRARIES})
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-g -O2")
set(CMAKE_EXE_LINKER_FLAGS "-s")
endif()
even if I give a LIBRARY_PATH in CMakeLists.txt it still uses /usr/lib
What should be done now ? would I do a booststrap.sh --prefix=/usr but wont that make duplicate copies ? also Do I need change all symlinks manually ?
or I'll remove previous installation (1.42) from repo (apt-get) ? I cannot remove all because there are dependant packages.
Solved by doing a ./bjam --layout=tagged install
Related
Context:
I have a cpp program built on MacOS 12.6 with the following CMakeLists.txt file.
cmake_minimum_required(VERSION 3.19.0)
project(cpp-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(cpp-test main.cpp)
add_library(test-helpers main.cpp ${PROJECT_SOURCE_DIR}/helpers.hpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
# this is super important in order for cmake to include the vcpkg search/lib paths!
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
# find library and its headers
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket/IXWebSocket.h)
find_library(IXWEBSOCKET_LIBRARY ixwebsocket)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
# include headers
include_directories(${IXWEBSOCKET_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
# Cmake will automatically fail the generation if the lib was not found, i.e is set to NOTFOUND
target_link_libraries(
${PROJECT_NAME} PRIVATE
${IXWEBSOCKET_LIBRARY}
OpenSSL::SSL
OpenSSL::Crypto
${CURL_LIBRARIES}
"-framework Foundation"
"-framework Security"
"-lz"
)
This compiles just fine. However, when I try to pull it into my Ubuntu VM and try to build it /build> cmake .., I get the following errors
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "cpp-test":
"IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of
"test-helpers":
"IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"
-- Generating done
What I have tried...
I have installed vcpkg and created my symlink ln -s /path/to/vcpkg /usr/local/bin/vcpkg.
I have installed ixwebsocket via vcpkg install ixwebsocket, but it seems that the CMAKE_TOOLCHAIN_FILE is not being parsed correctly.
I'm a bit lost, any help would be appreciated
This is not a great answer to the issue, but I ended up resolving it by building ixwebsocket via CMake instead.
It seems that vcpkg was not compatible with the linux distro in my VM.
I wanted to use DearImGui therefore I needed to either copy ImGui into the project or use a package manager, so I chose the latter. I'm currently using Conan as a my package manager, the file looks like this:
conanfile.txt
[requires]
boost/1.79.0
imgui/1.88
glad/0.1.36
glfw/3.3.7
[generators]
cmake_find_package
cmake_paths
CMakeDeps
CMakeToolchain
It has all the dependancies as a normal ImGui project would need as well as boost which had been downloaded as a binary previously and works fine, using just a normal header like #include <boost/asio.hpp>. I figure this happens because it was aleady installed.
I have a basic file structure that looks like this, prebuild:
conanfile.txt
CMakeLists.txt
src -
main.cpp
With this main CMakeLists I set up a linker with conan and simple setup instructions like the project name, executable, and the libraries
cmake_minimum_required(VERSION 3.23)
project(RenderCam CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/conan_paths.cmake)
add_executable(${PROJECT_NAME} src/main.cpp)
find_package(Boost 1.79.0 REQUIRED COMPONENTS thread system filesystem)
if(TARGET boost::boost)
target_link_libraries(${PROJECT_NAME} boost::boost)
endif()
find_package(glfw3 3.3 REQUIRED)
if(TARGET glfw)
message("Found GLFW")
target_link_libraries(${PROJECT_NAME} glfw)
endif()
find_package(imgui 1.88 REQUIRED)
if(TARGET imgui::imgui)
message("found imgui")
target_link_libraries(${PROJECT_NAME} imgui::imgui)
endif()
After running two commands (conan install .. and cmake .. -DCMAKE_BUILD_TYPE=Release) in the new build directory the CMake build responds with all the found messages for the project as well as the location of the files, which should be expected. Though when add the #include <imgui.h> to the main.cpp it states the file is not found which shouldn't be if I have linked it. On the other hand #include <boost/asio.hpp> has no errors and I can go upon my day with all of the commands. I would just like to include the directories and have tried multiple steps and guides before I took it here. For further reference, this is my conanprofile :
Configuration for profile default:
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=apple-clang
compiler.version=13
compiler.libcxx=libc++
build_type=Release
[options]
[conf]
[build_requires]
[env]
Don't mix up mutually exclusive generators like cmake_find_package vs CMakeDeps, or cmake_paths vs CMakeToolchain.
Here is a basic example of non-intrusive integration of conan:
conanfile.txt
[requires]
boost/1.79.0
imgui/1.88
glfw/3.3.7
[generators]
CMakeToolchain
CMakeDeps
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(RenderCam CXX)
find_package(Boost 1.79.0 REQUIRED thread system filesystem)
find_package(glfw3 3.3 REQUIRED)
find_package(imgui 1.88 REQUIRED)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::headers Boost::thread Boost::system Boost::filesystem glfw imgui::imgui)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
Install dependencies, configure & build:
mkdir build && cd build
conan install .. -s build_type=Release -b missing
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
I'm operating under a new learning curve here with c++ and using CMake in Visual Studio. Here is the partial code up until the point where I receive the error:
project(libfranka
VERSION 0.8.0
LANGUAGES CXX
)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
add_compile_options(/W0)
else()
add_compile_options(-Wall -Wextra)
endif()
set(THIRDPARTY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
find_package(Poco REQUIRED COMPONENTS Net Foundation)
find_package(Eigen3 REQUIRED)
Once it hits the first find_package is where I encounter the error:
Here is the code within FindPoco.cmake.
find_package(Poco COMPONENTS ${Poco_FIND_COMPONENTS} CONFIG QUIET)
if(Poco_FOUND)
return()
endif()
find_path(Poco_INCLUDE_DIR Poco/Poco.h)
mark_as_advanced(FORCE Poco_INCLUDE_DIR)
foreach(component ${Poco_FIND_COMPONENTS})
set(component_var "Poco_${component}_LIBRARY")
find_library(${component_var} Poco${component})
mark_as_advanced(FORCE ${component_var})
if(${component_var})
set(Poco_${component}_FOUND TRUE)
list(APPEND Poco_LIBRARIES ${component})
if(NOT TARGET Poco::${component})
add_library(Poco::${component} SHARED IMPORTED)
set_target_properties(Poco::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Poco_INCLUDE_DIR}
IMPORTED_LOCATION ${${component_var}}
)
endif()
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Poco
FOUND_VAR Poco_FOUND
REQUIRED_VARS Poco_INCLUDE_DIR Poco_LIBRARIES
VERSION_VAR Poco_VERSION
HANDLE_COMPONENTS
)
I installed poco using vcpkg in a directory titled vcpkg. Within the vcpkg directory is the libfranka directory, which houses the CMakeLists.txt file that I compile in Visual Studio. Here is an image of that directory:
Finally, here is the tutorial that I am using: https://frankaemika.github.io/docs/installation_windows.html#building-from-source
EDIT:
Per the link I followed the instructions for solving the build dependencies and here is an image of that:
Then I ran the CMakeLists.txt again and in the CMake Settings this is what I see:
Note also that I ran through the install of poco again and I noticed this and am unsure if it could be the source of the problem or if it means nothing (again, this was the out put after running vcpkg install poco):
After this I still receive the same error.
Does anyone see what it is that I am doing incorrectly?
Thank you!
I have been working on a library in C++ and have run into a bit of difficulty trying to integrate boost into my project. I kept the message that boost could not be found, but on the other hand, my fellow developer using Arch had no issues.
We figured out that this is because Linux Mint (at least with the libboost-all-dev package) installs the libraries to /usr/lib/x86_64-linux-gnu which is not searched by the FindBoost module. We fixed this by creating symbolic links:
ln -s /usr/lib/x86_64-linux-gnu/libboost* /usr/lib/
What I want to know: is there a better (more acceptable) way of fixing this because when I compile major projects, I do not run into this problem.
Here is CMakeLists.txt (with some omissions)
cmake_minimum_required(VERSION 2.8)
project(testlibrary CXX)
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_library(testlibrary STATIC ${SOURCE_MAIN})
target_link_libraries(testlibrary ${Boost_LIBRARIES})
You can set the hint BOOST_LIBRARYDIR:
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)
Alternative, you can set this when running CMake like this:
cmake -DBOOST_LIBRARYDIR="/usr/lib/x86_64-linux-gnu" <project_root>
If you just run:
cmake <project_root>
then FindBoost.cmake will look in the usual spots for your boost libaries.
See the documentation of FindBoost.cmake for your CMake version here.
I am trying to add Boost library to my project using the CMakeLists.txt in the follwing way:
set(BOOST_INCLUDEDIR "C:/boost_1_57_0")
set(BOOST_LIBRARYDIR "C:/boost_1_57_0/stage/lib")
find_package(Boost 1.57.0 COMPONENTS filesystem)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(test test.cpp)
target_link_libraries(test ${Boost_LIBRARIES})
However, I get the followng error: LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-1_57.lib'
libboost_filesystem-vc120-mt-1_57.lib is located in the stage/lib folder, so I don't know what is going on. I am compiling with Visual Studio 2013.
Any thoughts?
Try setting the Boost_USE_STATIC_LIBS and Boost_USE_MULTITHREADED CMake variables to ON before using find_package, i.e.:
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED ON )
find_package( Boost 1.57.0 COMPONENTS filesystem )
I've come across this problem before and it seems as though, on multithreaded windows systems, the Boost bootstrap installer compiles multithreaded, static libraries by default. However, the CMake FindBoost script (which is used by find_package) searches for single-threaded, dynamic libraries by default.
Since you're using VS compiler I'll say you're working on Windows.
The error refers to the linker, which is failing to find boost libraries, as noticed.
Taking into account that the library exists in the boost path, my solution was to do a file(COPY) for the specific library, as a last resort.
if(WIN32)
set(BOOST_ROOT "C:/boost_1_57_0")
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/)
endif()
find_package(Boost 1.57.0 EXACT REQUIRED system filesystem)
if(Boost_FOUND)
message(STATUS "found boost, Boost_LIBRARIES <" ${Boost_LIBRARIES} ">")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
else()
message(STATUS "boost not found")
endif()
target_link_libraries(boost_test ${Boost_LIBRARIES})
file(COPY "${Boost_LIBRARY_DIRS}/boost_filesystem-vc120-mt-1_57.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
You may add some log messages to the CMake in order to know the values returned in the
find_package.
Make sure the architecture (x64) matches.
$ cmake -A x64 ..
Use link_directories command before adding executables just like include_directories.
link_directories(${Boost_LIBRARY_DIRS})