I'm trying to install a library on osx 10.11 but when I use cmake, it prints the output below. This has worked in the past (as in it worked yesterday), but something seems to have gone wrong since then. I've looked for an answer but can't seem to find anything that works. My Xcode and Xcode command line tools are all up to date. My cmake is up to date. I tried uninstalling and reinstalling it to no avail. I've tested the c compiler and it's working as it should as far as I can tell. My openssl is also up to date, I tried reinstalling that as well without success. My Clang version is 7.0.0 (clang-700.0.72). It's probably something obvious that I'm missing. Any ideas would be greatly appreciated.
$ pwd
<*current directory*>
$ mkdir build
$ cd build
$ cmake ..
-- The C compiler identification is AppleClang 7.0.0.7000072
-- The CXX compiler identification is AppleClang 7.0.0.7000072
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- broken
CMake Error at /usr/local/Cellar/cmake/3.3.2/share/cmake/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: <*current directory*>/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_e9215/fast"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f
CMakeFiles/cmTC_e9215.dir/build.make CMakeFiles/cmTC_e9215.dir/build
Building C object CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-o CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o -c
<*current directory*>/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_e9215
/usr/local/Cellar/cmake/3.3.2/bin/cmake -E cmake_link_script
CMakeFiles/cmTC_e9215.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-Wl,-search_paths_first -Wl,-headerpad_max_install_names
/usr/local/opt/openssl/lib CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o -o
cmTC_e9215
ld: can't map file, errno=22 file '/usr/local/opt/openssl/lib' for
architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[1]: *** [cmTC_e9215] Error 1
make: *** [cmTC_e9215/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
-- Configuring incomplete, errors occurred!
See also "<*current directory*>/build/CMakeFiles/CMakeOutput.log".
See also "<*current directory*>/build/CMakeFiles/CMakeError.log".
This is the output of <current directory>/build/CMakeFiles/CMakeOutput.log:
The system is: Darwin - 15.0.0 - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
Build flags:
Id flags:
The output was:
0
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"
The C compiler identification is AppleClang, found in "<*current directory*>/build/CMakeFiles/3.3.2/CompilerIdC/a.out"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is AppleClang, found in "<*current directory*>/build/CMakeFiles/3.3.2/CompilerIdCXX/a.out"
And this is the output of <current directory>/build/CMakeFiles/CMakeError.log:
Determining if the C compiler works failed with the following output:
Change Dir: <*current directory*>/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_e9215/fast"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_e9215.dir/build.make CMakeFiles/cmTC_e9215.dir/build
Building C object CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -o CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o -c <*current directory*>/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_e9215
/usr/local/Cellar/cmake/3.3.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e9215.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Wl,-search_paths_first -Wl,-headerpad_max_install_names /usr/local/opt/openssl/lib CMakeFiles/cmTC_e9215.dir/testCCompiler.c.o -o cmTC_e9215
ld: can't map file, errno=22 file '/usr/local/opt/openssl/lib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_e9215] Error 1
make: *** [cmTC_e9215/fast] Error 2
EDIT:
Simple restart seemed to fix it. The obvious answer that I should have tried first. Sorry for wasting your time
The error is ld: can't map file, errno=22 file '/usr/local/opt/openssl/lib' for architecture x86_64. Looks to me like that is a directory, not a file. You can run the cmake command on the line above and try adding -L in front.
It turns out it was the obvious solution. Off and on again. There's now a different error but one I think I can fix. Sorry for wasting everyone's time
Related
I want to build a DLL library on macOS 12 (M1 Pro). I've install LLVM by Homebrew and created simple CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(Arkan)
set(BUILDDIR build)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR})
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Build the native Arkan library
add_library(arkan SHARED
lib/cpp/greeting.cpp
)
set_target_properties(arkan PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(arkan PROPERTIES SOVERSION 0)
set_target_properties(arkan PROPERTIES PUBLIC_HEADER lib/cpp/include/arkan.hpp)
And a toolchain file:
set(triple x86_64-windows-gnu)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER /opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER /opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
However, when I try to configure CMake:
cmake -DCMAKE_TOOLCHAIN_FILE=toolchains/x86_64_windows_gnu.cmake .
I get the next error:
-- The C compiler identification is Clang 13.0.1
-- The CXX compiler identification is Clang 13.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang
-- Check for working C compiler: /opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang - broken
CMake Error at /opt/homebrew/Cellar/cmake/3.23.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/user/Projects/arkan/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_06a5e/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_06a5e.dir/build.make CMakeFiles/cmTC_06a5e.dir/build
Building C object CMakeFiles/cmTC_06a5e.dir/testCCompiler.c.obj
/opt/homebrew/Cellar/llvm/13.0.1_1/bin/clang --target=x86_64-windows-gnu -MD -MT CMakeFiles/cmTC_06a5e.dir/testCCompiler.c.obj -MF CMakeFiles/cmTC_06a5e.dir/testCCompiler.c.obj.d -o CMakeFiles/cmTC_06a5e.dir/testCCompiler.c.obj -c /Users/denis/Projects/arkan/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_06a5e.exe
/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_06a5e.dir/link.txt --verbose=1
/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake -E rm -f CMakeFiles/cmTC_06a5e.dir/objects.a
/usr/bin/ar qc CMakeFiles/cmTC_06a5e.dir/objects.a #CMakeFiles/cmTC_06a5e.dir/objects1.rsp
ar: #CMakeFiles/cmTC_06a5e.dir/objects1.rsp: No such file or directory
make[1]: *** [cmTC_06a5e.exe] Error 1
make: *** [cmTC_06a5e/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
CMake continues to use LLVM from Xcode. What am I doing wrong?
I'm having trouble compiling a project requiring OpenMP using CMake and clang, I set my CMakeLists.txt like this
cmake_minimum_required(VERSION 3.20)
project(cmat C)
set(CMAKE_C_STANDARD 11)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
add_library(cmat SHARED cmat.c Calculation/_Basic_Calculate_.c Calculation/_Basic_Calculate_.h)
And when I started to build my project, it gave error
Undefined symbols for architecture x86_64:
"_omp_get_thread_num", referenced from:
_NmMulMat in _Basic_Calculate_.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libcmat.dylib] Error 1
make[2]: *** [CMakeFiles/cmat.dir/all] Error 2
make[1]: *** [CMakeFiles/cmat.dir/rule] Error 2
make: *** [cmat] Error 2
I've tried some of the other answers like this and this, but they just don't work for me.
The clang version for my Mac is 13.0.0 and CMake is of 3.21.3_1, I'm using Clion as IDE, and such command will work when compiling files by shell
clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp filename.c -o output
Great appreciate for your help.
You need to add -fopenmp to the linker flags as well by providing -DCMAKE_EXE_LINKER_FLAGS=-fopenmp [and any other options like -g].
In CLion (which I don't use) this would be specified in Preferences ->
Build, Execution, Deployment -> CMake -> CMake options as far as I understand the documentation.
Also please note that explicitly linking with -lomp is probably the wrong strategy, that happening should be a side-effect of specifying -fopenmp.
Trying to cross compile, here is the minimal example CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(hello VERSION 0.0.0 LANGUAGES C)
set(src "${CMAKE_CURRENT_BINARY_DIR}/src/main.c")
file(WRITE "${src}" "int main(){}")
add_executable(${PROJECT_NAME} "${src}")
$ brew install mingw-w64
$ mkdir 'cmake-build-win64-debug' && cd "$_"
$ cmake .. \
-DCMAKE_BUILD_TYPE='Debug' \
-DCMAKE_C_COMPILER='i686-w64-mingw32-gcc' \
-DCMAKE_CXX_COMPILER='i686-w64-mingw32-g++'
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc - broken
CMake Error at /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/usr/local/bin/i686-w64-mingw32-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: cmake-build-win64-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_f30ca/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_f30ca.dir/build.make CMakeFiles/cmTC_f30ca.dir/build
Building C object CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -o CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -c cmake-build-win64-debug/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_f30ca
/usr/local/Cellar/cmake/3.20.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_f30ca.dir/link.txt --verbose=1
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -o cmTC_f30ca
/usr/local/Cellar/mingw-w64/8.0.0_4/toolchain-i686/bin/i686-w64-mingw32-ld: Error: unable to disambiguate: -search_paths_first (did you mean --search_paths_first ?)
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_f30ca] Error 1
make: *** [cmTC_f30ca/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "cmake-build-win64-debug/CMakeFiles/CMakeOutput.log".
See also "cmake-build-win64-debug/CMakeFiles/CMakeError.log".
So I tried https://stackoverflow.com/a/54482619, specifically with
-DCMAKE_CXX_LINK_FLAGS='' \
-DHAVE_FLAG_SEARCH_PATHS_FIRST=0
But that didn't fix it. How do I build for Windows from macOS?
While running npm install in one of my project I'm getting this following error:
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/Library/Developer/CommandLineTools/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/user.name/.nvm/versions/node/v8.17.0/lib/node_modules/#devicefarmer/stf/node_modules/#julusian/jpeg-turbo/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_e8f1f/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_e8f1f.dir/build.make CMakeFiles/cmTC_e8f1f.dir/build
Building C object CMakeFiles/cmTC_e8f1f.dir/testCCompiler.c.o
/Library/Developer/CommandLineTools/usr/bin/cc -isysroot /Users/user.name/Library/Android/sdk -o CMakeFiles/cmTC_e8f1f.dir/testCCompiler.c.o -c /Users/user.name/.nvm/versions/node/v8.17.0/lib/node_modules/#devicefarmer/stf/node_modules/#julusian/jpeg-turbo/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_e8f1f
/usr/local/Cellar/cmake/3.19.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e8f1f.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/cc -isysroot /Users/user.name/Library/Android/sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/usr/local/opt/openssl#1.1/lib CMakeFiles/cmTC_e8f1f.dir/testCCompiler.c.o -o cmTC_e8f1f
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_e8f1f] Error 1
make: *** [cmTC_e8f1f/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
-- Configuring incomplete, errors occurred!
Tried uninstalling and installing CMake but no luck.
OS : MacOS Catalina 10.15.7
Node: v8.17.0
CMake: v3.19.4
I try to compile a simple CUDA "Hello World" using CMake on my Mac OSX 10.8.3.
Calling cmake . seems to succeed. Here is my CMakeList.txt:
project(HelloWorld)
cmake_minimum_required(VERSION 2.8)
FIND_PACKAGE(CUDA)
CUDA_INCLUDE_DIRECTORIES(/Developer/NVIDIA/CUDA-5.0/samples/common/inc)
CUDA_ADD_EXECUTABLE(helloWorld helloWorld.cu)
... and the output:
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- 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
-- Found CUDA: /Developer/NVIDIA/CUDA-5.0 (found version "5.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mennny/Documents/UNI/6_Semester/0_PMPP/1_exercises/cuda-hello-world
But calling make afterwards fails with the following error(s):
[100%] Building NVCC (Device) object CMakeFiles/helloWorld.dir//./helloWorld_generated_helloWorld.cu.o
clang: error: unsupported option '-dumpspecs'
clang: error: no input files
CMake Error at helloWorld_generated_helloWorld.cu.o.cmake:206 (message): Error generating /Users/mennny/Documents/UNI/6_Semester/0_PMPP/1_exercises/cuda-hello-world/CMakeFiles/helloWorld.dir//./helloWorld_generated_helloWorld.cu.o
make[2]: *** [CMakeFiles/helloWorld.dir/./helloWorld_generated_helloWorld.cu.o] Error 1
make[1]: *** [CMakeFiles/helloWorld.dir/all] Error 2
make: *** [all] Error 2
I googled the shown errors but couldn't find any sufficient answers.
Any ideas why make fails, although cmake succeeded.
Thanks for your help.
The default C compiler in XCode changed to CLang in OS X Lion. CLang is incompatible with nvcc, so you need to change the compiler that nvcc uses for non-cuda (host) code. Adding the following to your CMakeList.txt will work:
if (NOT DEFINED CUDA_HOST_COMPILER AND CMAKE_C_COMPILER_ID STREQUAL "Clang" AND EXISTS /usr/bin/gcc)
set(CUDA_HOST_COMPILER /usr/bin/gcc CACHE FILEPATH "Host side compiler used by NVCC")
message(STATUS "Setting CMAKE_HOST_COMPILER to /usr/bin/gcc instead of ${CMAKE_C_COMPILER}.")
endif()
Adjust the path to gcc if necessary.
If you don't want to change your CMakeLists.txt, it works if you set the environment variable CXX to "gcc" (assuming you don't have any other GCC in your path before the one in /usr/bin).
CMake will pick it up automatically.