I am trying to build this project, which has CUDA as a dependency. But the cmake script cannot find the CUDA installation on the system:
cls ~/workspace/gpucluster/cluster/build $ cmake ..
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /usr/share/cmake/Modules/FindCUDA.cmake:488 (message):
Specify CUDA_TOOLKIT_ROOT_DIR
Call Stack (most recent call first):
CMakeLists.txt:20 (find_package)
-- Configuring incomplete, errors occurred!
I've tried adding it as an environment variable to .bashrc, to no effect:
export CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-5.5
How do I Specify CUDA_TOOLKIT_ROOT_DIR correctly?
cmake mentioned CUDA_TOOLKIT_ROOT_DIR as cmake variable, not environment one. That's why it does not work when you put it into .bashrc. If you look into FindCUDA.cmake it clearly says that:
The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if the prefix
cannot be determined by the location of nvcc in the system path and REQUIRED
is specified to find_package(). To use a different installed version of the
toolkit set the environment variable CUDA_BIN_PATH before running cmake
(e.g. CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default /usr/local/cuda)
or set CUDA_TOOLKIT_ROOT_DIR after configuring. If you change the value of
CUDA_TOOLKIT_ROOT_DIR, various components that depend on the path will be
relocated.
So put CUDA_BIN_PATH into .bashrc or specify CUDA_TOOLKIT_ROOT_DIR to cmake:
cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-5.5 ..
FindCMake.cmake looks for /usr/local/cuda. In your case, that directory might not be there. Just create a symbolic link of that name to your actual CUDA installation directory:
$ sudo ln -s /usr/local/cuda-5.5 /usr/local/cuda
Your CMake should be able to generate the Makefile for your project now.
Maybe CUDA was installed from sources (and nvcc is not in the path). Then the script can not set CUDA_TOOLKIT_ROOT_DIR because of nvcc missing. For me it worked fine after running:
sudo apt install nvidia-cuda-toolkit
(This package might require several GiB of space)
Since CMake 3.8, FindCUDA is deprecated and the proper way of using CUDA in CMake projects is enabling it via project() or enable_language()
https://cmake.org/cmake/help/v3.8/release/3.8.html#cuda
In terminal, type nano ~/.bashrc. Then add the following lines to the file:
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib:/usr/local/lib
export CPLUS_INCLUDE_PATH=/usr/local/cuda/include
Save the file, then type source ~/.bashrc in terminal.
You may validate if CUDA path has been setup by typing nvcc --version in terminal.
In my case I had to make /usr/lib/cuda point to an actual CUDA installation. So I did:
ln -s /usr/lib/cuda /home/nvidia_libraries/cuda_10.2
I had cuda_10.2 installed locally in my home folder instead of system wide.
Related
OS: MacOS 12.4
Installed cmake with
brew install cmake
cmake version 3.23.3
Installed clang with
xcode-select --install
clang++ version is 13.1.6
Trying to build ccls:
git clone https://github.com/MaskRay/ccls.git
mkdir build && cd build
cmake ..
And getting following output
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- The C compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Setting build type to 'Release' as none was specified.
CMake Error at CMakeLists.txt:72 (find_package):
By not providing "FindClang.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Clang", but
CMake did not find one.
Could not find a package configuration file provided by "Clang" with any of
the following names:
ClangConfig.cmake
clang-config.cmake
Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
"Clang_DIR" to a directory containing one of the above files. If "Clang"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/Users/umed/projects/MaskRay/ccls/build/CMakeFiles/CMakeOutput.log".
See also "/Users/umed/projects/MaskRay/ccls/build/CMakeFiles/CMakeError.log".
Is there anyway to make brew's cmake work with system clang?
The question is not correct. CMake uses the system clang successfully, but it can't find clang libraries required by the project.
The Build manual lists the requirements, one of them is
Clang+LLVM headers and libraries, version >= 7
You get errors because you have not provided that dependency.
brew install llvm#13
I am developing on macOS with Apple-clang v12 being the default compiler via the Xcode installation. Since valgrind still does not support Big Sur and the Apple version does not support Google Sanitizers I have to manually install llvm v11.1 via homebrew to leverage Google Sanitizers to have any memory leak detection tool enabled.
Unfortunately this causes some issues with conan and its integration with CMake and CLion, my IDE. Since my dependencies do not provide binaries for my architecture using clang instead of Apple-clang they have to built locally. Unfortunately conan and CMake error when invoking them with two contradictory error messages:
conan install /Users/near/Code/personal/blight -if=/Users/near/Code/personal/blight/cmake-build-debug -pr=LLVM11Debug --build=missing
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=clang
compiler.libcxx=libstdc++
compiler.version=11
os=Macos
os_build=Macos
[options]
[build_requires]
[env]
fmt/7.1.3: WARN: Package binary is corrupted, removing: 2284170e72f485ebb586c7bd784f294475c25e5e
conanfile.txt: Installing package
Requirements
fmt/7.1.3 from 'conan-center' - Cache
spdlog/1.8.5 from 'conan-center' - Cache
Packages
fmt/7.1.3:2284170e72f485ebb586c7bd784f294475c25e5e - Build
spdlog/1.8.5:b744aef5cdad24eec65bb267843e16ad74c9ad39 - Build
Installing (downloading, building) binaries...
fmt/7.1.3: WARN: Build folder is dirty, removing it: /Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e
fmt/7.1.3: Copying sources to build folder
fmt/7.1.3: Building your package in /Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e
fmt/7.1.3: Generator cmake created conanbuildinfo.cmake
fmt/7.1.3: Calling build()
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: called inside local cache
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Adjusting fPIC flag (ON)
-- Conan: Compiler Clang>=8, checking major version 11
-- Conan: Checking correct version: 12
CMake Error at conanbuildinfo.cmake:402 (message):
Detected a mismatch for the compiler version between your conan profile
settings and CMake:
Compiler version specified in your conan profile: 11
Compiler version detected in CMake: 12.0
Please check your conan profile settings (conan profile show
[default|your_profile_name])
P.S. You may set CONAN_DISABLE_CHECK_COMPILER CMake variable in order to
disable this check.
Call Stack (most recent call first):
conanbuildinfo.cmake:499 (conan_error_compiler_version)
conanbuildinfo.cmake:589 (check_compiler_version)
conanbuildinfo.cmake:141 (conan_check_compiler)
CMakeLists.txt:5 (conan_basic_setup)
-- Configuring incomplete, errors occurred!
See also "/Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e/build_subfolder/CMakeFiles/CMakeOutput.log".
See also "/Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e/build_subfolder/CMakeFiles/CMakeError.log".
fmt/7.1.3:
fmt/7.1.3: ERROR: Package '2284170e72f485ebb586c7bd784f294475c25e5e' build failed
fmt/7.1.3: WARN: Build folder /Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e
ERROR: fmt/7.1.3: Error in build() method, line 63
cmake = self._configure_cmake()
while calling '_configure_cmake', line 56
self._cmake.configure(build_folder=self._build_subfolder)
ConanException: Error 1 while executing cd '/Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e/build_subfolder' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="11" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="/Users/near/.conan/data/fmt/7.1.3/_/_/package/2284170e72f485ebb586c7bd784f294475c25e5e" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCONAN_CMAKE_POSITION_INDEPENDENT_CODE="ON" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DFMT_DOC="False" -DFMT_TEST="False" -DFMT_INSTALL="True" -DFMT_LIB_DIR="lib" -Wno-dev '/Users/near/.conan/data/fmt/7.1.3/_/_/build/2284170e72f485ebb586c7bd784f294475c25e5e'
"/Users/near/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/203.7717.62/CLion.app/Contents/bin/cmake/mac/bin/cmake" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -G "CodeBlocks - Unix Makefiles" /Users/near/Code/personal/blight
-- The CXX compiler identification is Clang 11.1.0
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /Users/near/Code/personal/blight/cmake-build-debug
CMake Error at cmake-build-debug/conanbuildinfo.cmake:626 (message):
Detected a mismatch for the compiler version between your conan profile
settings and CMake:
Compiler version specified in your conan profile: 12.0
Compiler version detected in CMake: 11.1
Please check your conan profile settings (conan profile show
[default|your_profile_name])
P.S. You may set CONAN_DISABLE_CHECK_COMPILER CMake variable in order to
disable this check.
Call Stack (most recent call first):
cmake-build-debug/conanbuildinfo.cmake:728 (conan_error_compiler_version)
cmake-build-debug/conanbuildinfo.cmake:813 (check_compiler_version)
cmake-build-debug/conanbuildinfo.cmake:365 (conan_check_compiler)
CMakeLists.txt:13 (conan_basic_setup)
-- Configuring incomplete, errors occurred!
See also "/Users/near/Code/personal/blight/cmake-build-debug/CMakeFiles/CMakeOutput.log".
This is the output seen in the CMake output window of CLion. The first invocation has CMake think Apple-clang is my compiler while conan is configured to use the llvm version and on the second step (most likely invoked by conan_basic_setup in my CMakeLists.txt) the correct CMake compiler is chosen but Conan ends up without a profile hence a version mismatch.
In the CLion settings I have already overwritten the c++ compiler with the llvm v11.1 compiler:
What's the correct solution to properly configure both to use the llvm v11.1 compiler? I personally do not want to enable the CONAN_DISABLE_CHECK_COMPILER CMake variable as it is unclear which compiler will be used to compile dependencies in the end.
Previously posted questions only suggest intentionally using the higher version which is not what I want:
CMake Error: mismatch for the compiler version between your conan profile
Both packages I see in your log file, spdlog and fmt, are available as header only configuration.
So if these are your only dependencies, you can simply set the option to use them header only, and this will eliminate the problem since there is nothing to build for these packages.
One way doing so is adding the settings into the profile you use, into the option section, like that
[options]
fmt:header_only=True
spdlog:header_only=True
I was able to find a solution albeit by disabling the Conan integration first. With a clean build directory I went in there and had to invoke Conan manually as follows:
CC=clang CXX=clang++ conan install .. -pr=LLVM11Debug --build=missing
Afterwards it was possible run build with CMake and clang 11 configured in the UI of CLion. The issue was that the Conan integration plugin does not provide a direct way to set the compiler using the environment variables and it does not get the compiler from the Toolchain options in CLion.
I am trying to build a LLVM from a working copy I have from another machine. The original source is build using configure and make. However, on the new systems the same build method fails (I have tried make clean). I tried the cmake option and it says the following:
Basically there seems to be some left over files from the earlier build, so the question is how do I remove it, elegantly, i.e not with a linux command but using the LLVM build system itself. make distclean says "No rule to make target `disctclean'. Stop."
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:57 (message):
Apparently there is a previous in-source build,
probably as the result of running `configure' and `make' on
/Users/me/scp/llvm_release.
This may cause problems. The suspicious files are:
/Users/me/scp/llvm_release/lib/Target/AArch64/AArch64GenAsmWriter.inc;
...
...
/Users/me/scp/llvm_release/lib/Target/XCore/XCoreGenSubtargetInfo.inc
/Users/me/scp/llvm_release/include/llvm/IR/Intrinsics.gen
Please clean the source directory.
-- Configuring incomplete, errors occurred!
The LLVM build system does not provide a solution for this problem. You can start from scratch with clean sources or use some linux shell voodoo to get rid of all .gen files.
This is one reason why we use a separate build directory in the directions here:
http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary
The easiest way would be to restart with a clean set of source and avoid using configure and make in the source directory.
If you checked the source out using source control you can just use that to remove all the untracked files and reset all the modified ones.
Just remove the mentioned files:
Users/me/scp/llvm_release/lib/Target/AArch64/AArch64GenAsmWriter.inc;
...
...
/Users/me/scp/llvm_release/lib/Target/XCore/XCoreGenSubtargetInfo.inc
/Users/me/scp/llvm_release/include/llvm/IR/Intrinsics.gen
and then run run make or cmake or ninja again. If it complains that a file is missing then copy the missing file from the original LLVM source code.
I'm trying to compile libarchive using cmake -G Xcode libarchive according to the official build instructions
I ve cmake 2.8.12 installed via mac port and use the current CMakeList.txt
cmake -G Xcode libarchive outputs
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:177 (SET_TARGET_PROPERTIES):
set_target_properties called with incorrect number of arguments.
CMake Error at CMakeLists.txt:193 (INSTALL_MAN):
Unknown CMake command "INSTALL_MAN".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Configure from the top-level directory (the one containing the README file):
$ cmake -G Xcode .
the subsidiary CMakeLists.txt files in various directories are not complete and cannot be used by themselves.
I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.