I'm trying to link OpenSSL library to my project using CMake.
I'm using Ubuntu 22.04.
All I do is
cmake_minimum_required(VERSION 3.4.1)
project (test)
add_executable(test test.cpp)
find_package(OpenSSL REQUIRED)
target_link_libraries(
test PRIVATE OPENSSL::SSL
)
And I get an error Target "test" links to target "OPENSSL::SSL" but the target was not found.
I had installed OpenSSL with "sudo apt install libssl-dev" so it must be installed.
What can I do here?
Related
I'm trying to cross compile from Win10 to Raspian OS on the Raspberry Pi 4. For this reason I use the Ubuntu 22.04 LTS WSL. I installed gcc/g++, CMake, Ninja, SDL2, Vulkan SDK, aarch64-linux-gnu-gcc/g++.
In the CMakeLists.txt I call find_package(SDL2 REQUIRED) and find_package(Vulkan REQUIRED).
When I compile with the normal gcc and g++ there is no problem, but when I try the aarch64-linux-gnu-gcc and aarch64-linux-gnu-g++
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
Error message:
CMake Error at CMakeLists.txt:66 (find_package):
By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2", but
CMake did not find one.
Could not find a package configuration file provided by "SDL2" with any of
the following names:
SDL2Config.cmake
sdl2-config.cmake
Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set
"SDL2_DIR" to a directory containing one of the above files. If "SDL2"
provides a separate development package or SDK, be sure it has been
installed.
The libs can be found in the folder /usr/lib/x86_64-linux-gnu
Why are they not in the folder /usr/lib/aarch64-linux-gnu?
How can I use or install them for the aarch64-linux-gnu-gcc/g++?
Thank you in advance!
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
In this link at the bottom aarch64-linux-gnu files are mentioned, but there are non installed in my /usr/lib/aarch64-linux-gnu folder
https://ubuntu.pkgs.org/20.04/ubuntu-universe-arm64/libsdl2-dev_2.0.10+dfsg1-3_arm64.deb.html
I have an executable in cmake that depends on libssh being installed on the system.
I use this to install it:
sudo apt-get install -y libssh-dev
This is my Cmake:
cmake_minimum_required(VERSION 3.5.0)
project(validateTensor VERSION 0.0.1)
find_package(gflags QUIET)
add_executable(myapplication
"myapplication.cpp"
)
target_link_libraries(myapplication gflags teamApplication -lssh)
add_dependencies(myapplication teamApplication)
My question is how can I use cmake to check if libshh is installed on the system before adding the executable. If it is not installed then I want to exclude the executable from the build but not have the build fail.
How to check if a library (libssh) is installed with Cmake before adding executable
With find_library.
find_library(HAVE_SSH NAMES ssh)
add_executable(myapplication
myapplication.cpp
)
target_link_libraries(myapplication gflags teamApplication)
if (HAVE_SSH)
target_link_libraries(myapplication ssh)
endif()
No need to add_dependencies(myapplication teamApplication) - target_link_libraries already "does that".
This is my CMakeLists.txt, it works correctly on Windows and installs the dll to bin and the lib to .lib.
add_library(test SHARED)
target_sources(test PRIVATE test.cpp)
install(TARGETS test ARCHIVE DESTINATION /home/user/cmake_test/out/lib)
install(TARGETS test RUNTIME DESTINATION /home/user/cmake_test/out/bin)
On Linux the DESTINATION seems to be ignored and cmake tries to install test.so to /usr/local/lib/test.so. I could use CMAKE_INSTALL_PREFIX but I can't see anything in the documentation that suggests that this approach shouldn't work on Linux.
I've tried cmake 16 from the Ubuntu 20.04 repos and the latest cmake 3.19.1. Make and Ninja builds both have the same behaviour.
I've installed libevent on macOS -
$ brew install libevent
I'm trying to import it in my CMakeLists.txt -
cmake_minimum_required(VERSION 3.14)
project(xyz)
set(CMAKE_CXX_STANDARD 17)
find_package(libevent REQUIRED)
I get the following CMake error -
CMake Error at CMakeLists.txt:6 (find_package):
By not providing "Findlibevent.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "libevent",
but CMake did not find one.
Could not find a package configuration file provided by "libevent" with any
of the following names:
libeventConfig.cmake
libevent-config.cmake
Add the installation prefix of "libevent" to CMAKE_PREFIX_PATH or set
"libevent_DIR" to a directory containing one of the above files. If
"libevent" provides a separate development package or SDK, be sure it has
been installed.
Could someone please tell how to import libevent installed in the system in CMake?
I have same trouble but I work arond this by adding:
link_directories(
/usr/local/lib
/usr/lib
)
INCLUDE_DIRECTORIES(
/usr/local/include/
/usr/include
)
It just tell the Makefile where to find libevent header and library.
I'm currently developing a Kalman Filtering library using Eigen and I've successfully gotten it working on my development Mac. Now I'm trying to set it up with Travis CI and CMake is having trouble with finding the package. First I sudo apt install libeigen3-dev and then attempt to run cmake with the following configuration:
cmake_minimum_required(VERSION 3.0)
project(KFilter VERSION 0.1.0)
find_package (Eigen3 REQUIRED NO_MODULE)
add_library(KFilter KFilter.cpp)
target_link_libraries(KFilter Eigen3::Eigen)
This builds just fine on my Mac, but in Travis CI it errors out with the following:
CMake Error at CMakeLists.txt:5 (add_library):
Target "KFilter" links to target "Eigen3::Eigen" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
Why is would I be getting this error at line 5 when the find_package seems to be successful? I'm following this guide from the Eigen website.
Travis CI is running Ubuntu 16.04 with CMake 3.12 and the Eigen3 debian package, while my Mac is running CMake 3.13 with Eigen installed through homebrew. I'm really confused as to why CMake is behaving differently.
You don't mention which version of Eigen3 is being used in each case.
It looks like between Eigen3 3.2 and 3.3 it changed from using FindEigen3.cmake to Eigen3Config.cmake. This changed how to include Eigen3 into a project and in 3.3 it uses Eigen3::Eigen3.
But as it turns out on Ubuntu 16.04 the package is libeigen3-dev (3.3~beta1-2) and 3.3 beta versions didn't export Eigen3::Eigen3 instead it contains:
add_definitions ( ${EIGEN3_DEFINITIONS} )
include_directories ( ${EIGEN3_INCLUDE_DIRS} )
So just remove target_link_libraries(KFilter Eigen3::Eigen) and it should be fine.
What worked for me using Ubuntu 16.04 was to remove the target_link_libraries(KFilter Eigen3::Eigen) and change in my source file the following line #include <eigen3/Eigen/Dense>