CMake fails to find OpenSSL for me. Brew's OpenSSL is located at /usr/local/Cellar/openssl/1.0.2s/. I'm on macOS Catalina.
My CMakeLists.txt looks like this:
[...]
set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/1.0.2s)
find_package(OpenSSL REQUIRED)
target_include_directories(myapp PUBLIC ${OPENSSL_INCLUDE_DIR})
message(STATUS "OpenSSL: Version ${OPENSSL_VERSION}")
message(STATUS "OpenSSL: include dir at ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL: libraries at ${OPENSSL_LIBRARIES} ${OPENSSL_SSL_LIBRARIES}")
[...]
target_link_libraries(myapp
${CMAKE_DL_LIBS}
${OPENSSL_LIBRARIES}
${OPENSSL_SSL_LIBRARIES}
Qt5::Core
)
Outputs:
-- OpenSSL: Version 1.0.2s
-- OpenSSL: include dir at /usr/local/Cellar/openssl/1.0.2s/include
-- OpenSSL: libraries at /usr/lib/libssl.dylib;/usr/lib/libcrypto.dylib /usr/lib/libssl.dylib
So CMake found the correct include dir, but the libraries were taken from my system's installation of OpenSSL? Even though I specified OPENSSL_ROOT_DIR as per the documentation.
Why can't it find these files?
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.a
/usr/local/Cellar/openssl/1.0.2s/lib/pkgconfig/libssl.pc
/usr/local/Cellar/openssl/1.0.2s/lib/pkgconfig/libcrypto.pc
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.a
If I ignore this, and proceed with compiling my program I get:
ld: cannot link directly with /usr/lib/libcrypto.dylib for architecture x86_64
I tried brew upgrade openssl for what it's worth.
I run CMake from CLion and I include -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/Users/me/Qt/5.9.7/clang_64
CMake cache was the issue. In CLion, I can properly rebuild/refresh CMake by going to Tools -> CMake -> Reset cache & reload project. After this, the output is:
-- OpenSSL: Version 1.0.2s
-- OpenSSL: include dir at /usr/local/Cellar/openssl/1.0.2s/include
-- OpenSSL: libraries at /usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib;/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.dylib /usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib
Which seems to be correct, and answers my question.
In addition, I had to do: brew switch openssl 1.0.2s to compile correctly.
Related
I've been fighting freetype2 for a week trying to get it to work on Windows 32 bit but it just won't. My CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_CXX_STANDARD 17)
project(template-project) # change the name here
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
list(APPEND CMAKE_PREFIX_PATH "D:/Installs/ProgFiles/glew")
find_package( OpenGL REQUIRED )
include_directories( ${OPENGL_INCLUDE_DIRS} )
# this is so stupid
set(CMAKE_SIZEOF_VOID_P 4)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
# ensure 32 bit on clang
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target i386-pc-windows-msvc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target i386-pc-windows-msvc")
add_definitions("--target=i386-pc-windows-msvc")
endif()
set(FT_DISABLE_HARFBUZZ TRUE)
target_include_directories(${PROJECT_NAME} PRIVATE
libraries/minhook/include
libraries/gd.h/include
libraries/gd.h/
libraries/imgui
libraries/glad/include
libraries/stb
libraries/freetype2/include
)
add_subdirectory(libraries/minhook)
add_subdirectory(libraries/cocos-headers)
add_subdirectory(libraries/glfw)
add_subdirectory(libraries/glm)
add_subdirectory(libraries/freetype2)
target_link_libraries( ${PROJECT_NAME} ${OPENGL_LIBRARIES} glfw )
if( MSVC )
if(${CMAKE_VERSION} VERSION_LESS "3.6.0")
message( "\n\t[ WARNING ]\n\n\tCMake version lower than 3.6.\n\n\t - Please update CMake and rerun; OR\n\t - Manually set 'GLFW-CMake-starter' as StartUp Project in Visual Studio.\n" )
else()
set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT GLFW-CMake-starter )
endif()
endif()
target_link_libraries(${PROJECT_NAME} opengl32.lib minhook cocos2d rpcrt4.lib glm ${PROJECT_SOURCE_DIR}/libraries/freetype2/objs/Win32/Release/freetype.lib)
The biggest issue in the output are these lines:
[cmake] -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
[cmake] -- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
[cmake] -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
[cmake] -- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
[cmake] -- Could NOT find BZip2 (missing: BZIP2_LIBRARIES BZIP2_INCLUDE_DIR)
[cmake] -- Could NOT find BrotliDec (missing: BROTLIDEC_INCLUDE_DIRS BROTLIDEC_LIBRARIES)
I am on windows and completely unsure how to fix these. I've tried installing zlib via mingw32, and I've tried linking it the same way I do things like minhook and glad to no avail.
I recommend a different approach than manual downloading of opensource dependencies when using MinGW. Instead of searching for individual binary downloads switch to use msys2 to install MinGW and use the package management of msys2 to all of your dependent open source libraries.
The first step is to remove your current MinGW install so you have no conflicting / possibly incompatible MinGW dlls in your PATH that may cause you problems in the future when executing your programs.
After that install msys2: How to install MinGW-w64 and MSYS2?
Then to install your dependencies for 32 bit open the mingw32 terminal which by default is installed in "C:\msys64\mingw32.exe" and use the package manager of msys2 pacman to install the dependent packages.
The web page for msys2 has a convenient package search feature at the top center of this page: https://packages.msys2.org/queue
Lets start with zlib from your dependencies. Type in zlib in the search box and press search. Type mingw-w64-zlib then look for i686 packages for mingw to find the correct package for 32 bit mingw. I found the following link for zlib for mingw32 has the following page: https://packages.msys2.org/package/mingw-w64-i686-zlib?repo=mingw32
The install instructions for that are listed in the center of the page: pacman -S mingw-w64-i686-zlib
so copy this command to the mingw32 terminal:
JMDLAPTOP1+dresc#JMDLAPTOP1 MINGW32 ~
# pacman -S mingw-w64-i686-zlib
resolving dependencies...
looking for conflicting packages...
Packages (1) mingw-w64-i686-zlib-1.2.13-2
Total Download Size: 0.10 MiB
Total Installed Size: 0.39 MiB
:: Proceed with installation? [Y/n]
Press Y to install this package.
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
mingw-w64-i686-zlib-1.2.13... 102.8 KiB 126 KiB/s 00:01 [###############################] 100%
(1/1) checking keys in keyring [###############################] 100%
(1/1) checking package integrity [###############################] 100%
(1/1) loading package files [###############################] 100%
(1/1) checking for file conflicts [###############################] 100%
(1/1) checking available disk space [###############################] 100%
:: Processing package changes...
(1/1) installing mingw-w64-i686-zlib [###############################] 100%
JMDLAPTOP1+dresc#JMDLAPTOP1 MINGW32 ~
Continue a similar process for the other dependent packages.
I have a project depends on SFML lib on C++. I trying to make it with CMake.
CMakeLists.txt is:
cmake_minimum_required(VERSION 3.16.3)
project(3D_Renderer_from_scratch)
set(CMAKE_CXX_STANDARD 17)
include_directories(headers source)
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML COMPONENTS window graphics system)
set(SOURCES
Main.cpp
source/Application.cpp
source/Box.cpp
source/Camera.cpp
source/FileReader.cpp
source/KeyboardHandler.cpp
source/Sphere.cpp
source/Triangle.cpp
source/Window.cpp
source/World.cpp
)
add_executable(executable ${SOURCES})
target_link_libraries(executable ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
After running cmake . I have the following error:
$ cmake .
-- Requested SFML configuration (Static) was not found
CMake Warning at CMakeLists.txt:10 (find_package):
Found package configuration file:
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake
but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
FOUND.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcjohn974/3D_Renderer_from_scratch
How can I fix it ? (sfml lib is already installed)
As already mentioned in the comments (why not write it as an answer?), CMake was looking for static SFML libraries and it most likely just found shared libraries.
Either make sure that static libraries (the ones with the -s suffix) are provided.
Or don't request static libraries, which you can achieve be not setting SFML_STATIC_LIBRARIES.
Following the instructions on their github repo I managed to build and install both libraries
paho-mqtt-c and paho-mqtt-cpp
in a custom directory
C:\mqtt\paho-c
C:\mqtt\paho-cpp
Now I'm trying to add those libraries in my project. My CMakelists.txt is as follows
cmake_minimum_required(VERSION 3.21)
enable_language(CXX)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
project(mqtt_test)
add_executable(mqtt_test main.cpp)
However, cmake insists on asking me where to find them.
Could NOT find PahoMqttC (missing: PAHO_MQTT_C_LIBRARIES PAHO_MQTT_C_INCLUDE_DIRS)
Why do I need to tell cmake again where to find C libraries? I think that was the job of find_package to also include those variables because I set it up on building and installation time.
Operating system: Windows 11 x64.
cmake version: 3.22.2
cmake generator: Ninja
C compiler: 11.2.0 (cygwin64)
C++ compiler: 11.2.0 (cygwin64)
EDIT: I manually specified the paths
set(PAHO_MQTT_C_LIBRARIES C:/mqtt/paho-c/lib/libpaho-mqtt3a-static.a)
set(PAHO_MQTT_C_INCLUDE_DIRS C:/mqtt/paho-c/include)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
However I'm getting a compilation error:
fatal error: mqtt/async_client.h: No such file or directory
61 | #include "mqtt/async_client.h"
I know how to solve it by manually adding the include paths in my cmakelist but I'm trying to figure out how to use their cmake module properly. find_package doesn't seem to do that.
Or I'm missing something.
I want to compile SealPIR library using emscripten to generate a wasm file.
When using this command:
emcmake cmake .
I get this error:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "FindSEAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SEAL", but
CMake did not find one.
Could not find a package configuration file provided by "SEAL" (requested
version 3.2.0) with any of the following names:
SEALConfig.cmake
seal-config.cmake
Add the installation prefix of "SEAL" to CMAKE_PREFIX_PATH or set
"SEAL_DIR" to a directory containing one of the above files. If "SEAL"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/Zied/webassembly/SealPIR/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake . -DCMAKE_TOOLCHAIN_FILE=/home/Zied/webassembly/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/home/Zied/webassembly/emsdk/node/14.15.5_64bit/bin/node"' failed (1)
SEAL is correctly installed. when i run the same command without emcmake it works just fine.
This is my CMakeList
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(SealPIR VERSION 2.1 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(main
main.cpp
)
add_library(sealpir STATIC
pir.cpp
pir_client.cpp
pir_server.cpp
)
find_package(SEAL 3.2.0 EXACT REQUIRED)
target_link_libraries(main sealpir SEAL::seal)
When using a toolchain file for cross compiling, CMake will by default disable system libraries. It won't search into any directory to avoid finding files that is not compatible with the target system.
You think you didn't used a toolchain file? Think again! emcmake hides that from you. Look carefully at the error output.
Here you compiled the SEAL library, but you installed it in the default path, which is /usr/local.
We can tell CMake to explicitly search there, but I wouldn't recommend, but you can try if it works:
emcmake cmake . -CMAKE_PREFIX_PATH=/usr/local
The proper solution would be to create a directory with all the emscripten libraries in it:
# In the SEAL build directory
emcmake cmake .. -DCMAKE_INSTALL_PREFIX=/home/anblic/webassembly/install
Then after installing the libraries in that directory, you can set the prefix path in the same directory as the install path:
# Assuming you're in a build/ subdirectory
emcmake cmake .. -DCMAKE_PREFIX_PATH=/home/anblic/webassembly/install
I am trying to use boost thread for my project in a Ubuntu machine. I download boost 1.58.0 via apt-get in ubuntu and use Cmake for building the c++ project.
In my CMakeLists.txt, I have
find_package(Boost 1.58.0 REQUIRED)
include_directories( ${Boost_INCLUDE_DIR} )
message(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries( Sparse3D ${COLMAP_LIBRARIES} )
It turns out Cmake can't find the boost library
-- Boost_INCLUDE_DIR: /usr/include
-- Boost_LIBRARIES:
I then checked online and figured out that I may need to specify the library, and changed the CMakeLists.txt to
find_package(Boost 1.58.0 COMPONENTS system filesystem thread REQUIRED)
But CMake can't find boost_thread. Here is the CMake output:
-- Found Glew
-- Includes : /usr/include
-- Libraries : /usr/lib/x86_64-linux-gnu/libGLEW.so
-- __cplusplus is 201103
-- --> Do not link with Boost.Thread
-- Boost version: 1.58.0
-- Boost include dirs: /usr/include
-- Boost libraries:
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Boost version: 1.58.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_thread
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:20 (find_package)
-- GLM_INCLUDE_DIR = /usr/local/include
-- GLM included at /usr/local/include
-- Boost_LIBRARIES: /usr/include
-- Boost_LIBRARIES:
But libboost_thread.so.1.58.0 does exist in /usr/lib/x86_64-linux-gnu.
Thank you all in advance.
I again did a fresh installation of boost 1.71, and suddenly CMake is able to find libboost-thread. What I found is that CMake findpackage can't find libboost-thread with boost 1.58 (installed with apt-get), but can find that with boost 1.71. Previously, I guess it's probably because boost 1.58 was not removed completely which causes CMake to fail to find boost-thread 1.71. Besides, even though boost 1.51 is removed, CMake can still find boost 1.48 in ubuntu.