adding boost library to clion on MacOsX - c++

Hello i installed boost using comand
brew install boost
it installed 1.66.0 version
I edited CMakeLists in this way
cmake_minimum_required(VERSION 3.8)
project(fraction)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp source/Fraction.cpp headers/Fraction.h headers/MyStack.h unitTest.cpp)
add_executable(fraction ${SOURCE_FILES})
set(BOOST_ROOT "/usr/local/Cellar/boost/1.66.0")
find_package(Boost 1.66.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
I don't have any error, in file unitTest.cpp I want to write test and I'm trying to include this
#include <boost/test/unit_test.hpp>
but I got error "Cannot find 'boost'"
What I do wrong ?

Ok I find why it doesn't work, brew didn't link boost
on high sierra it should be in this way
if usr/local/include and usr/local/Frameworks don't exist it must be created by
sudo mkdir usr/local/include
sudo mkdir usr/local/Frameworks
after that we can chown usr/local/include by
sudo chown -R $(whoami) $(brew --prefix)/*

Related

Assimp isn't found by CMake

Before saying anything: Yes, I googled and searched for a long time before asking this here so 99% the solution of other similar questions doesn't work for me.
I have an opengl application that uses the following libraries:
glfw
imgui
glad
stb
assimp
glm
filebrowser (an extension of imgui for dialog boxes)
all these libraries are in a folder called external each one in its dir.
Moreover, glfw, assimp, glm are git submodules of my repo so they're downloaded when i clone my repo with git clone --recursive mygitrepo.
You can have a better understanding of the structure of the project looking at my git repo.
My idea was to use the add_subdirectories to make them compile with their own CMakeLists and my main one looks like this:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
add_subdirectory(external/glfw)
add_subdirectory(external/assimp)
add_subdirectory(external/glad)
add_subdirectory(external/imgui)
add_subdirectory(external/stb)
add_subdirectory(external/glm)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
find_package(OpenGL REQUIRED)
target_include_directories(${PROJECT_NAME}
PUBLIC external/glfw/include
PUBLIC external/assimp/include
PUBLIC external/glm
PUBLIC external
PUBLIC src
)
target_link_libraries(${PROJECT_NAME} glfw glad imgui stb glm Engine assimp FileBrowser)
The project was developed with visual studio on windows and I want to compile it on linux without using visualstudio. The cmake doesn't give me any errors but when i run the make command it gives me this error:
#include <assimp/quaternion.h> there's no file or directory with this name.
like i didn't put the assimp include folder in the cmake (but i did).
Do you have any idea how to make it works? I want to make a bash script to install all the dependencies and tools needed like xorg-dev, build-essential, git, cmake, make etc. So if there's any simple fix using some bash commands it's ok for me.
I figured out how to fix it. I just installed conan and used it to download and find assimp. So I removed assimp, glm, glfw and glad from 'external' folder and just added a conanfile.txt.
Here the conanfile.txt:
[requires]
assimp/5.2.2
glfw/3.3.7
glm/0.9.9.8
glad/0.1.35
[generators]
cmake_find_package
cmake_paths
my main CMakeLists.txt now it's as following:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
# Retrieve conan.cmake
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif ()
include("${CMAKE_BINARY_DIR}/conan.cmake")
conan_cmake_run(CONANFILE "conanfile.txt" BASIC_SETUP UPDATE BUILD missing)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
find_package(OpenGL REQUIRED)
find_package(glad REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(assimp REQUIRED)
add_subdirectory(external/stb)
add_subdirectory(external/imgui)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
file(MAKE_DIRECTORY
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
function(install_file_to_bin file_name)
file(INSTALL "${CMAKE_SOURCE_DIR}/Shaders/${file_name}" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
endfunction()
install_file_to_bin(1.model_loading.fs)
install_file_to_bin(1.model_loading.vs)
install_file_to_bin(4.1.fshader.fs)
install_file_to_bin(4.1.vshader.vs)
install_file_to_bin(animated_model_loading.fs)
install_file_to_bin(animated_model_loading.gs)
install_file_to_bin(animated_model_loading.vs)
install_file_to_bin(bb.vs)
install_file_to_bin(bb.fs)
install_file_to_bin(default.frag)
install_file_to_bin(default.fs)
install_file_to_bin(default.geom)
install_file_to_bin(default.vert)
install_file_to_bin(default.vs)
install_file_to_bin(floor.fs)
install_file_to_bin(floor.vs)
install_file_to_bin(framebuffer.frag)
install_file_to_bin(framebuffer.vert)
install_file_to_bin(grey_model.fs)
install_file_to_bin(grey_model.vs)
install_file_to_bin(hover.fs)
install_file_to_bin(hover.vs)
install_file_to_bin(influence_of_single_bone.fs)
install_file_to_bin(influence_of_single_bone.vs)
install_file_to_bin(mouse_shader.fs)
install_file_to_bin(mouse_shader.vs)
install_file_to_bin(normal_visualizer.fs)
install_file_to_bin(normal_visualizer.gs)
install_file_to_bin(normal_visualizer.vs)
install_file_to_bin(no_lighting_shader.fs)
install_file_to_bin(no_lighting_shader.vs)
install_file_to_bin(num_bones_visualization.fs)
install_file_to_bin(num_bones_visualization.vs)
install_file_to_bin(screen_shader.fs)
install_file_to_bin(screen_shader.vs)
install_file_to_bin(selected.fs)
install_file_to_bin(selected.vs)
install_file_to_bin(smooth_lighting_shader.fs)
install_file_to_bin(smooth_lighting_shader.vs)
install_file_to_bin(wireframe.vs)
install_file_to_bin(wireframe.fs)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
include_directories(
${OpenGL_INCLUDE_DIRS}
${glad_INCLUDE_DIRS}
${glfw3_INCLUDE_DIRS}
${glm_INCLUDE_DIRS}
${assimp_INCLUDE_DIRS}
external
src
)
target_link_libraries(${PROJECT_NAME}
${OpenGL_LIBRARIES}
${glad_LIBRARIES}
${glfw3_LIBRARIES}
${glm_LIBRARIES}
stb
${assimp_LIBRARIES}
imgui
FileBrowser
Engine
)
Some notes that can be usefull for other people having this troubles:
Assimp has some linking problem when used with conan because it seems that it doesn't download everything but just what you need so it works for the #include but it complains in the linking phase. Adding the following 3 rows fixed the problem:
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
I have a script to install everything you need on linux and install the stuff with conan, launch the cmake etc.. Even if I install the conan packages with the command conan install .. [...] I need the conan.cmake file so the lines at the beginning looking for the conan.cmake files fixed a lot of problems
The shell scripts is the following:
#!/bin/bash
sudo apt-get update
sudo apt-get install git
sudo apt-get install xorg-dev
sudo apt-get install make
sudo apt-get install cmake
sudo apt-get install build-essential
cd build
rm -rf *
conan install .. --settings os="Linux" --settings compiler="gcc" --settings compiler.version=11 --build missing
cmake -S .. -B . -D CMAKE_BUILD_TYPE=Release
make
cd build
Hope this can help you

Cannot find "Findaws-lambda-runtime.cmake" on ubuntu18.04

Trying to build the hello world example, but the cmake always complain
By not providing "Findaws-lambda-runtime.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"aws-lambda-runtime", but CMake did not find one.
Environment
OS : ubuntu18.04.3 LTS,64bits
install curl by : sudo apt-get install libcurl4-openssl-dev
install cmake by ubuntu software(cmake version 3.16.1)
Steps to build and install aws lambda cpp
git clone https://github.com/awslabs/aws-lambda-cpp.git
cd aws-lambda-cpp
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=${PWD}/install
make -j2
sudo make install
CmakeLists.txt(omit another part, want to make sure find_package works first)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/")
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
find_package(aws-lambda-runtime REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")
I do not use the ec2 to build the project, how could I tell the cmake where should it find the aws-lambda-runtime?
Edit :
Based on the suggestion of Yevhenii Mamontov, I change the CMakeLists.txt to
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
#check the prefix paths are correct or wrong
foreach(path ${CMAKE_PREFIX_PATH})
message("Path: " ${path})
endforeach(path)
find_package(aws-lambda-runtime REQUIRED)
But it come with different error message
CMake Error at
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake:6
(include): include could not find load file:
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/#CMAKE_PROJECT_NAME#-targets.cmake
I tried with different paths
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install")
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
and tried to do not add any new path, but all of them give the same error messages
Edit 2 :
Find a way to make it work
Remove the contents of /home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake
set path as set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
However, this solution is awkward, should ask the cmake do not search from the path "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake" first
Edit 3:
The solution I written in Edit 2 do not work. It fail when I add
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-lambda-runtime)
Error messages are
Target "aws_cpp_test" links to target "AWS::aws-lambda-runtime" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
Could you try to set CMAKE_PREFIX_PATH just before the find_package?
Something like this:
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
The first set() creates a variable with the path to your lib cmake folder.
The second set() appends to CMAKE_PREFIX_PATH one more path to search for any package that you've indicated in find_package().
Find out the solution, all you need to do are set the path of the aws library installed.
Example:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(encoder LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-lambda-cpp/build/install/)
set(AWS_LAMBDA_CPP_SDK ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-sdk-cpp/build/install/)
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH};${AWS_LAMBDA_CPP_SDK}")
find_package(CURL REQUIRED)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS s3)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME}
${CURL_LIBRARIES}
AWS::aws-lambda-runtime
${AWSSDK_LINK_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
You may need to install following libs on your ubuntu if you haven't
sudo apt-get install zlib1g-dev libssl-dev libcurl4-openssl-dev
I got the same error, the answer marked as solution worked pretty well, but I also found tha this works:
set(aws-lambda-runtime_DIR /lib/aws-lambda/lib64/aws-lambda-runtime/cmake/)
I am using CMake 3.13 and had the lambda runtime installed on "/lib/aws-lambda" when running tha cmake as instructed by the installation instructions:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/lib/aws-lambda

ubuntu cmake link boost staticly

I have an c++ code and it depends on boost filesystem
I just installed it like this
sudo apt-get install libboost-dev
and with cmake I used:
find_package( Boost 1.5.9 REQUIRED COMPONENTS filesystem system)
MESSAGE("Boost information:")
MESSAGE(" Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
MESSAGE(" Boost_LIBRARIES: ${Boost_LIBRARIES}")
MESSAGE(" Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
target_link_libraries(project ${Boost_LIBRARIES})
And I ran make and its compile without error but its compile it as shared library
I just search for make it static so what I did first I uninstall the libboost-dev with
sudo apt-get purge --remove libboost-dev
sudo apt-get purge --auto-remove libboost-dev
and I downloaded the boost source from
here
I downloaded the boost_1_66_0.tar.gz
I extracted it in home/build and ran this command:
./boostrap.sh
./b2 --target=static
sudo ./b2 install
All of the above was done without error
but I failed to link that to cmake for compile static library I tried this in cmake:
set(Boost_INCLUDE_DIR home/build/boost)
set(Boost_LIBRARY_DIR home/build/boost/stage/lib)
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
add_executable(project main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )
But seems I failed to link and it shows this error:
fatal error: file system.hpp: No such file or directory

Build fails with OpenCV on cmake

I'm trying to compile a project using OpenCV 2.4 on ubuntu 16.04. I installed opencv using apt-get:
sudo apt-get install libopencv-dev
sudo apt-get install libopencv-nonfree-dev
However, when compiling the project I'm getting the following error message:
undefined reference to `cv::imread(std::string const&, int)'
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.5)
project(Ex)
find_package(OpenCV REQUIRED )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c99")
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}}")
message(STATUS "OpenCV_LIBS=${OpenCV_LIBS}")
set(SOURCE_FILES main.cpp)
add_executable(Ex ${SOURCE_FILES})
target_link_libraries(Ex ${OpenCV_LIBS})
set_property(TARGET Ex PROPERTY C_STANDARD 99)
Does anyone know how to solve this?
Edit
The output of the second message is
OpenCV_LIBS=opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d

cmake cannot detect boost multiple installation

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