How to build Windows DLL on macOS? - macos

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?

Related

Compiling libxsmm on Macbook air m1

I tried to compile the libxsmm library on my Macbook air m1 (arm64) using the following commands:
git clone --branch 1.17 https://github.com/hfp/libxsmm
cd libxsmm
make generator
cp bin/libxsmm_gemm_generator $HOME/bin
cd ..
However, I got an error that an Intel Architecture or compatible CPU required:
(base) yonatan#Yonatans-MacBook-Air libxsmm % make generator
cc -DNDEBUG -D__STATIC=1 -DLIBXSMM_BUILD=1 -Iinclude -I./src -fPIC -Wno-pass-failed -Wall -O2 -pthread -c ./src/libxsmm_generator_gemm_driver.c -o obj/intel64/libxsmm_generator_gemm_driver.o
In file included from ./src/libxsmm_generator_gemm_driver.c:11:
In file included from include/libxsmm.h:44:
In file included from include/libxsmm_dnn_convolution.h:14:
In file included from include/libxsmm_dnn.h:14:
In file included from include/libxsmm_typedefs.h:14:
include/libxsmm_macros.h:61:5: error: Intel Architecture or compatible CPU required!
# error Intel Architecture or compatible CPU required!
^
1 error generated.
make: [obj/intel64/libxsmm_generator_gemm_driver.o] Error 1 (ignored)
--------------------------------------------------------------
In case of assembler error, perhaps GNU Binutils are outdated.
See https://github.com/hfp/libxsmm#outdated-binutils
--------------------------------------------------------------
make: *** [obj/intel64/libxsmm_generator_gemm_driver.o] Error 1
(base) yonatan#Yonatans-MacBook-Air libxsmm %
Is there any way to compile or install the libxsmm library on my Mac? I need this library to set up the SeiSol platform (see: documentation https://seissol.readthedocs.io/en/latest/compilation.html) for my studies.
Let me know if any further details are needed. Thanks!

Cross-compile for Windows from macOS? - i686-w64-mingw32-ld: Error: unable to disambiguate: -search_paths_first (did you mean --search_paths_first ?)

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?

Linker Error: g++ 5.4 Ubuntu 16.04

The error I have is :
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.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
-- Detecting C compile features
-- Detecting C compile features - 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
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.58.0
-- Found MLPACK: /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cortana/ClionProjects/hmmClassification/build
Scanning dependencies of target hmm
[ 50%] Building CXX object CMakeFiles/hmm.dir/source/main.cpp.o
[100%] Linking CXX executable hmm
/usr/bin/ld: CMakeFiles/hmm.dir/source/main.cpp.o: undefined reference to symbol '_ZN5boost15program_options3argB5cxx11E'
//usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hmm.dir/build.make:95: recipe for target 'hmm' failed
make[2]: *** [hmm] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/hmm.dir/all' failed
make[1]: *** [CMakeFiles/hmm.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2
I have included the --std=c++11 tag in CMakeLists.txt
Here is the cmake :
cmake_minimum_required(VERSION 3.3)
project(hmm)
set(PROJECT_VERSION "0.0.1")
# Default configuration values. These must be before the project command or
# they won't work in Windows.
# If no build type is specified, default to "Release"
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"None Debug Release RelWithDebInfo MinSizeRel"
FORCE)
endif()
# Install to "dist" directory in Windows for testing and as a staging directory
# for the installer.
if (WIN32 AND NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX dist CACHE STRING "Install path prefix.")
endif()
if (NOT MSVC)
# Enable the C++11 standard
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
endif()
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost REQUIRED)
find_package(MLPACK REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(${Boost_DEFINITIONS})
include_directories(${MLPACK_INCLUDE_DIRS})
link_directories(${MLPACK_LIBRARY_DIRS})
add_definitions(${MLPACK_DEFINITIONS})
# Global CMake options
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
# Testing configuration
enable_testing()
#add_subdirectory(source)
file(GLOB SOURCE_FILES
source/main.cpp)
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME}
${Boost_LIBRARIES}
${MLPACK_LIBRARIES})
I dont understand the problem here. Boost and MLPack (required in the code) are properly installed. Also i have used the --std=c++11 tag that was the solution to this problem in previous answers. How do I fix this problem?
Edit:
Output of verbose cmake :
/usr/bin/c++ -I/home/cortana/ClionProjects/hmmClassification/build -I/home/cortana/ClionProjects/hmmClassification -I/usr/local/include -std=c++11 -std=c++11 -g -o CMakeFiles/hmm.dir/source/main.cpp.o -c /home/cortana/ClionProjects/hmmClassification/source/main.cpp
[100%] Linking CXX executable hmm
/usr/bin/cmake -E cmake_link_script CMakeFiles/hmm.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -std=c++11 -g CMakeFiles/hmm.dir/source/main.cpp.o -o hmm -L/usr/local/lib -rdynamic /usr/local/lib/libmlpack.so -Wl,-rpath,/usr/local/lib
/usr/bin/ld: CMakeFiles/hmm.dir/source/main.cpp.o: undefined reference to symbol '_ZN5boost15program_options3argB5cxx11E'
//usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hmm.dir/build.make:98: recipe for target 'hmm' failed
make[2]: *** [hmm] Error 1
make[2]: Leaving directory '/home/cortana/ClionProjects/hmmClassification/build'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/hmm.dir/all' failed
make[1]: *** [CMakeFiles/hmm.dir/all] Error 2
make[1]: Leaving directory '/home/cortana/ClionProjects/hmmClassification/build'
Makefile:97: recipe for target 'all' failed
make: *** [all] Error 2
The project tree is (if its relevant) :
.
├── cmake
│   └── FindMLPACK.cmake
├── CMakeLists.txt
└── source
├── CMakeLists.txt
├── HMMEval.h
├── HMMExperiments.h
├── hmm.h
├── hmm_impl.h
├── HMMPredict.h
├── HMMTrain.h
└── main.cpp
Although you are calling find_package(Boost REQUIRED), you are not specifying any components of Boost to be found, so ${Boost_LIBRARIES} ends up containing nothing, and even though you specify
target_link_libraries(hmm
${MLPACK_LIBRARIES}
${Boost_LIBRARIES})
it doesn't work. So the solution is to add the required components of Boost to the call to find_package():
find_package(Boost COMPONENTS program_options REQUIRED)
Ideally I think that your CMake script FindMLPACK.cmake should find the Boost dependencies too and append them to ${MLPACK_LIBRARIES}, but that is a different issue.
according to this question, have you tried to link with the bost libraries after the MLPack ones?
I believe you could do it by permuting the last two lines in your cmake file.

Cmake not working. C compiler failing

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

CUDA 5.0, CMake and Make failing on OSX 10.8.3

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.

Resources