I am tryting to setup a build of a project on my Macbook which should use GCC with both Conan & CMake.
I have set the following environment variables:
export CC=/usr/local/bin/gcc-12
export CXX=/usr/local/bin/g++-12
When I run Conan all libraries are installed (and built if missing):
conan install ../ --build=missing
My .conan/profiles/default shows that Conan has used gcc-12.
[settings]
os=Macos
os_build=Macos
arch=armv8
arch_build=armv8
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]
When I run CMake with:
cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc-12 -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-12 ../
I get the following error
cmake ../
-- Ubuntu: Using Conan to manage dependencies
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory:
~/some-dir/build
CMake Error at build/conanbuildinfo.cmake:1812 (message):
Incorrect 'apple-clang', is not the one detected by CMake: 'GNU'
Call Stack (most recent call first):
build/conanbuildinfo.cmake:1369 (conan_check_compiler)
CMakeLists.txt:62 (conan_basic_setup)
build/conanbuildinfo.cmake:1369 contains the following:
message(FATAL_ERROR "Incorrect '${CONAN_COMPILER}', is not the one
detected by CMake: '${CMAKE_CXX_COMPILER_ID}'")
This indicates that CMake has detected the Conan compiler as AppleClang NOT GCC
I cannot see where conanbuildinfo.cmake gets the value for CONAN_COMPILER from.
How can I force CMake & Conan to use GCC-12?
Related
I'm writing a small C++ cross-platform library which uses CMake, Clang, Ninja and Conan. I've managed to cross-compile the library, but I'm having difficulties adding a Conan package. For a test, I've added fmt as a dependecy in conanfile like so:
conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMakeToolchain
class App(ConanFile):
name = "example_library"
version = "1.0.0"
settings = "os", "compiler", "build_type", "arch"
requires = "fmt/9.0.0"
default_options = {"fmt:shared": True}
And I've made two conan profiles:
clanglinux
[settings]
os=Linux
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=14
build_type=Release
[env]
CC=clang
CXX=clang++
CONAN_CMAKE_GENERATOR=Ninja
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
[options]
[build_requires]
clangwindows
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=14
build_type=Release
[env]
CC=clang
CXX=clang++
CONAN_CMAKE_GENERATOR=Ninja
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
[options]
[build_requires]
When executing conan install for a native platform (in this case Windows) everything works as expected. However, when I try to cross-compile the dependency for Linux with conan install . --build=missing -pr:h=clanglinux -pr:b=clangwindows, I get the following error:
CMake Error at CMakeLists.txt:231 (add_library):
The install of the fmt target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
This error occurs after Conan's build() function get's called for the fmt package. It calls cmake with the following arguments:
cmake -G "Ninja"
-DCMAKE_TOOLCHAIN_FILE="C:/Users/name.surname/.conan/data/fmt/9.0.0/_/_/build/048e14dd7a94fe623d3253718843fce321999150/build/generators/conan_toolchain.cmake"
-DCMAKE_INSTALL_PREFIX="C:/Users/name.surname/.conan/data/fmt/9.0.0/_/_/package/048e14dd7a94fe623d3253718843fce321999150"
-DFMT_DOC="OFF"
-DFMT_TEST="OFF"
-DFMT_INSTALL="ON"
-DFMT_LIB_DIR="lib"
-DFMT_OS="ON"
-DCMAKE_POLICY_DEFAULT_CMP0091="NEW"
-DCMAKE_BUILD_TYPE="Release"
"C:\Users\name.surname\.conan\data\fmt\9.0.0\_\_\build\048e14dd7a94fe623d3253718843fce321999150\src"
As far as I know (correct me if I'm wrong), this command is specified in the fmt conanfile and I don't have a lot of control over it. But according to the error message, I should add -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON argument to the command. Is there a way to achieve this?
Also, why is it necessary to set CMAKE_BUILD_WITH_INSTALL_RPATH variable, can it be avoided altogether?
Thanks.
Trying to compile dot11decrypt on debian, installed apt-get install libtins4.0 and apt-get install libtins-dev, but cmake .. can't find package libtins, heres the error:
CMake Error at CMakeLists.txt:4 (FIND_PACKAGE):
By not providing "Findlibtins.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "libtins", but
CMake did not find one.
Could not find a package configuration file provided by "libtins" with any
of the following names:
libtinsConfig.cmake
libtins-config.cmake
Add the installation prefix of "libtins" to CMAKE_PREFIX_PATH or set
"libtins_DIR" to a directory containing one of the above files. If
"libtins" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/user/dot11decrypt/build/CMakeFiles/CMakeOutput.log".
cat:dot11decrypt/CMakeLists.txt
1. CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
2. PROJECT(dot11decrypt)
3.
4. FIND_PACKAGE(libtins REQUIRED)
5.
6. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
7.
8. ADD_EXECUTABLE(dot11decrypt dot11decrypt.cpp)
9. TARGET_LINK_LIBRARIES(dot11decrypt ${LIBTINS_LIBRARIES} pthread)
find / -name Findlibtins.cmake or libtinsConfig.cmake brings no result.
I found those files on internet but still no success, i think i have to install something but don't know what.
I went with Tsyvarev solution.
# installing missing dependencies for libtins
apt-get install libpcap-dev libssl-dev cmake
# installing libtins
git clone https://github.com/mfontanini/libtins.git
cd libtins
mkdir build
cd build
cmake ../
make
checkinstall
Now cmake will reach dot11decrypt missing files.
# installing dot11decrypt
git clone https://github.com/mfontanini/dot11decrypt.git
cd dot11decrypt/
mkdir build
cd build/
cmake ../
make
Now you should have dot11decrypt executable.
If i would have to do it again i would try Alex Reinking solution first.
You don't need to compile from source... find_package is a very flexible configuration point! You'll just need to provide your own find module that is sufficient for the build. Fortunately, this is very simple. Here's what I did:
$ https://github.com/mfontanini/dot11decrypt
$ cd dot11decrypt
$ mkdir _patches
$ vim _patches/Findlibtins.cmake
$ cat _patches/Findlibtins.cmake
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBTINS REQUIRED libtins)
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_MODULE_PATH=$PWD/_patches
CMake Deprecation Warning at CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'libtins'
-- Found libtins, version 4.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/dot11decrypt/build
$ cmake --build build/
[ 50%] Building CXX object CMakeFiles/dot11decrypt.dir/dot11decrypt.cpp.o
/home/alex/test/dot11decrypt/dot11decrypt.cpp: In function ‘void decrypt_traffic(unique_fd, const string&, decrypter_tuple)’:
/home/alex/test/dot11decrypt/dot11decrypt.cpp:333:39: warning: ‘Tins::Sniffer::Sniffer(const string&, unsigned int, bool, const string&, bool)’ is deprecated [-Wdeprecated-declarations]
333 | Sniffer sniffer(iface, 2500, false);
| ^
In file included from /usr/include/tins/dns.h:38,
from /usr/include/tins/tins.h:33,
from /home/alex/test/dot11decrypt/dot11decrypt.cpp:25:
/usr/include/tins/sniffer.h:369:5: note: declared here
369 | TINS_DEPRECATED(Sniffer(const std::string& device, unsigned max_packet_size,
| ^~~~~~~~~~~~~~~
[100%] Linking CXX executable dot11decrypt
[100%] Built target dot11decrypt
The key here is to create a minimal Find module. This is just two lines on my system since it isn't meant to be reusable...
# _patches/Findlibtins.cmake
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBTINS REQUIRED libtins)
This just delegates the responsibility of setting the LIBTINS_LIBRARIES to pkg-config. To connect this find module to the build, I just set -DCMAKE_MODULE_PATH=$PWD/_patches at the CMake configure command line.
Also, you should definitely open a bug report with the dot11decrypt author about their broken and outdated build. Notice the strongly worded deprecation warning in the logs I posted.
I want to use vcpkg in a CMake project in Windows, because I need boost and xerces that are both handled by this package manager.
I've the following CMakeLists.txt:
cmake_minimum_required (VERSION 3.12.0)
project (myproj)
set (CMAKE_PREFIX_PATH ${XERCES_ROOT})
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
# set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules)
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package (XercesC CONFIG REQUIRED)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "binary dir is ${CMAKE_BINARY_DIR}")
include_directories (${CMAKE_BINARY_DIR}/${PROJECT_NAME}/)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories (${Boost_INCLUDE_DIRS})
include_directories (${XercesC_INCLUDE_DIRS})
set (PROJECT_SRC
code.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
add_dependencies (${PROJECT_NAME} UPDATE_RESOURCES)
target_link_libraries (${PROJECT_NAME} ${Boost_LIBRARIES} XercesC::XercesC)
Boost and xerces-c are installed with vcpkg. Since I'm using Visual Studio Code I'm setting vcpkg variables in settings.json:
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE" : "some/path/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
When I run che CMake I obtain following errors:
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:2132 (message):
[cmake] Unable to find the requested Boost libraries.
[cmake]
[cmake] Unable to find the Boost header files. Please set BOOST_ROOT to the root
[cmake] directory containing Boost or BOOST_INCLUDEDIR to the directory containing
[cmake] Boost's headers.
[cmake] Call Stack (most recent call first):
[cmake] D:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake:233 (_find_package)
[cmake] src/myroject/CMakeLists.txt:24 (find_package)
[cmake]
[cmake]
[cmake] CMake Error at D:/Projects/vcpkg/installed/x64-windows/share/xercesc/vcpkg-cmake-wrapper.cmake:1 (_find_package):
[cmake] Could not find a package configuration file provided by "XercesC" with any
[cmake] of the following names:
[cmake]
[cmake] XercesCConfig.cmake
[cmake] xercesc-config.cmake
[cmake]
[cmake] Add the installation prefix of "XercesC" to CMAKE_PREFIX_PATH or set
[cmake] "XercesC_DIR" to a directory containing one of the above files. If
[cmake] "XercesC" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake] Call Stack (most recent call first):
[cmake] D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake:189 (include)
[cmake] src/ZLA/CMakeLists.txt:25 (find_package)
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "D:/Projects/zla/build/vscode/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
At the moment I've installed xerces with vcpkg commands, while boost is currently not installed, but I was expecting that during the execution of the cmake command, vcpkg will download and build needed build packages.
I've tried also the command line:
cmake -DCMAKE_TOOLCHAIN_FILE=D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ../
but the result is the same.
What I'm doing wrong? How can I use vcpkg successfully?
In theory it's as simple as (assuming vcpkg as installed in C:/vcpkg as it is for github actions);
Install your "foo" package with vcpkg install foo
Make sure your CMakeLists.txt finds and uses the package with;
find_package(FOO)
# Use these instead of the package doesn't have proper cmake
package support.
# find_path(FOO_INCLUDE_DIRS foo.h)
# find_library(FOO_LIBRARYS foo)
include_directories(${FOO_INCLUDE_DIRS})
target_link_libraries(myprogram ${FOO_LIBRARIES})
Run cmake with
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
But... this didn't work for me until I added --triplet x64-windows to the vcpkg install command.
The DCMAKE_TOOLCHAIN_FILE sets the various CMAKE_(SYSTEM_)?(PREFIX|LIBRARY|INCLUDE|FRAMEWORK)_PATH variables to enable the find_*() cmake functions to work, but note that these paths include the VCPKG_TARGET_TRIPLET. In my case the package install with vcpkg install <foo> defaulted to x86-windows but then invoking cmake with -DCMAKE_TOOLCHAIN_FILE=C:/.... defaulted to x64-windows so it couldn't find the the package.
Currently vcpkg defaults to the older x86 target, but modern Visual Studio (as used by githup actions) defaults to x64. The fix was to install the package with vcpkg -triplet x64-windows install <foo>. It took me way too long going down too many red-herring rabbit holes to discover this.
You need to install the packages beforehand (using vcpkg install ).
(Then you could specify the toolchain as a CMake option:
-DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake
but this won't work if you already specify a toolchain, such as when cross-compiling.)
"include" it, instead, to avoid this problem:
Add this line to the project CMakeLists.txt before find_package():
include(/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake)
boost is currently not installed, but I was expecting that during the execution of the cmake command, vcpkg will download and build needed build packages.
This is not the case as far as I know. You need to install the packages you want with vcpkg beforehand for the triplet you plan to use (i.e. x64-windows). You will then need to ensure that the correct triplet is being used when you run CMake (check the VCPKG_TARGET_TRIPLET variable in your CMakeCache.txt). If it's incorrect, you can change it and re-configure using CMake.
Additionally, based on the error output you're getting, it doesn't seem that xerces has been installed properly either using vcpkg. You can check what is installed with vcpkg by running:
vcpkg list --triplet x64-windows
I had the same issue and just solved it either with:
set(CURL_DIR "C:/Libs/vcpkg/installed/x64-windows/share/curl")
or
list(APPEND CMAKE_PREFIX_PATH "C:/Libs/vcpkg/packages/curl_x64-windows/share/curl/")
I installed vcpkg under C:/Libs
I am using CLion to write C++ programs and I am using MinGW.But I have some files missing namely-Make,C Compiler and C++ Compiler which are not found.I am using MinGW Installation Manager to install the packages but I don't know the exact names of the packages I have to install.
What are the names of the packages I need to install to get rid of this error?(I need the specific names that I can get in the MinGW Installation manager.)
I am also getting these error messages-
"C:\Program Files\JetBrains\CLion 2017.1.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles"
C:\Users\Lenovo\CLionProjects\untitled
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Thanks for any help!!
tps://i.stack.imgur.com/SFWFU.png
Under the "Basic Setup" category in the installer, you need to select and install mingw32-gcc-g++ and mingw32-make.
There is a project that was developed for linux environment. Now I am trying to build this on windows using CMake.
I keep trying to build the project and always get this error:
CMake Error at C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindGTest.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
C:/Users/awy9/git/cmake_modules/modules/SigeoGTest.cmake:21 (find_package)
C:/Users/awy9/git/cmake_modules/modules/SigeoInit.cmake:29 (include)
CMakeLists.txt:12 (include)
How can I set these variables to work on this project now on Windows?
Honestly It's not the best idea to set hardcoded variables like you've done with GTEST_LIBRARY and GTEST_MAIN_LIBRARY.
I had the exact same problem. I was using gtest 1.7.0 on windows and getting the same error.
Turns out "GTest" should be "gtest" (not capitalized).
So the code in my CMakeLists.txt became:
find_package(gtest REQUIRED)
Note that I was using CMake 3.9
EDIT
I would highly recommend following this guide now:
http://crascit.com/2015/07/25/cmake-gtest/
It is by far the best method I have found to use unbuilt gtest and gmock in your cmake project.
UPDATE
#Tsyvarev helped me solving the first problem and I quote him:
This is standard CMake message, when requested package(GTest in your case) is not found. You should install GTest before configuring your project. Or, if you already have installed it into non-standard location, pass this location via GTEST_ROOT variable: cmake -DGTEST_ROOT= ...
As alternative for the passing variable to cmake, you can set environment variable: set GTEST_ROOT=
This solved the problem with the value of GTEST_INCLUDE_DIR, but I still had these errors:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageH andleStandardArgs.cmake:148 (message): Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
SOLUTION
I figured that on Windows environment some values are different from what the manuals say.
After compiling Gtest, I got two libs: gtest.lib and gtest_main.lib
Then, I set these filepath variables:
GTEST_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest.lib
GTEST_MAIN_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest_main.lib
Now everything is working!
Thank you
I've come up with a similar issue when building my project through GitHub Actions on Windows platform.
Even if I export the CMAKE_PREFIX_PATH to enable the find_package(GTest REQUIRED) to properly find the framework library (Windows is a bit nasty BTW), it continues to fail with Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY). Note that it correctly fetches the include directory.
After digging a little bit deeper into the issue I realized that on Windows the command cmake --build . --target install without any --config options, builds the library in Debug configuration, contrary to Linux and macOS.
If you are then building your project in Release, e.g. cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . --config Release --target install, the find_package(GTest REQUIRED) won't find any GTest library because it searches for the nonexistent Release build.
In this case a better solution is to install GTest in Release mode w.r.t. hardcoding the library paths to fetch the Debug\ directory builds.
I attach also the GitHub Action steps which may be helpful for someone:
steps:
- name: Clone GTest
shell: bash
working-directory: ${{runner.workspace}}
run: git clone https://github.com/google/googletest.git
- name: Create GTest Build Environment
shell: bash
working-directory: ${{runner.workspace}}/googletest
run: cmake -E make_directory build
- name: Configure GTest CMake
shell: bash
working-directory: ${{runner.workspace}}/googletest/build
run: cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_FLAGS=-std=c++11
- name: Install GTest
shell: bash
working-directory: ${{runner.workspace}}/googletest/build
run: cmake --build . --config $BUILD_TYPE --target install || sudo cmake --build . --config $BUILD_TYPE --target install
- name: Export CMAKE_PREFIX_PATH on Windows
shell: bash
if: runner.os == 'Windows'
run: echo '::set-env name=CMAKE_PREFIX_PATH::C:/Program Files (x86)/googletest-distribution'
- name: Checkout
uses: actions/checkout#v2
- ... your project build steps