tags:

views:

351

answers:

3

Hi all

I figured out that CUDA does not work in 64bit mode on my mac (or couldn't get it running so far). Therefore I decided to compile everything for 32bit.

I use cmake 2.8 and added the following options

add_definitions(-Wall -m32)
set(CUDA_64_BIT_DEVICE_CODE OFF)
set(CMAKE_MODULE_LINKER_FLAGS -m32)

However when it tries to link it it does something like this:

/usr/bin/c++    -mmacosx-version-min=10.6 -Wl,-search_paths_first -headerpad_max_install_names  CMakeFiles/SimpleTestsCUDA.dir/BlockMatrix.cpp.o CMakeFiles/SimpleTestsCUDA.dir/Matrix.cpp.o ./SimpleTestsCUDA_generated_SimpleTests.cu.o ./SimpleTestsCUDA_generated_BlockMatrix.cu.o  -o SimpleTestsCUDA  /usr/local/cuda/lib/libcudart.dylib /usr/local/cuda/lib/libcuda.dylib 

Which fails with a lot of "file is not of required architecture" warnings from ld. Now if I add manually -m32 to the command above it works. However I have no idea how to teach cmake to add -m32 to every gcc (or ld) invocation. So far it does it for nvcc and gcc, but not for linking..

+2  A: 

see above

set(CMAKE_C_FLAGS -m32) set(CMAKE_CXX_FLAGS -m32)

Nils
Now that you've solved the problem, you should mark the answer as accepted, so the rest of us can see that it's answered when we're looking at the question list. :)
Brooks Moses
You have to wait like three days or so until you can accept your own answer :D So I accepted the answer by Bill Hoffman..
Nils
+2  A: 

If you set the env var LDFLAGS before you run cmake on the project it will work as well:

export LDFLAGS=-m32 cmake ../source

Bill Hoffman
+1  A: 

Another solution might be to say:

if (Apple)
  set (CMAKE_OSX_ARCHITECTURES i386)
  set (CUDA_64_BIT_DEVICE_CODE OFF) 
endif (Apple)

Hope this helps.

kashif