3

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..

malat
  • 12,152
  • 13
  • 89
  • 158
Nils
  • 13,319
  • 19
  • 86
  • 108
  • 2
    Figured out that it works if I invoke cmake with the following flags: -DCMAKE_C_FLAGS=-m32 --DCMAKE_CXX_FLAGS=-m32 – Nils Apr 11 '10 at 15:33
  • I think I figured it out.. set(CMAKE_C_FLAGS -m32) set(CMAKE_CXX_FLAGS -m32) – Nils Apr 11 '10 at 15:50

3 Answers3

4

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

export LDFLAGS=-m32
cmake ../source
malat
  • 12,152
  • 13
  • 89
  • 158
Bill Hoffman
  • 1,742
  • 11
  • 12
3

see above

set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
malat
  • 12,152
  • 13
  • 89
  • 158
Nils
  • 13,319
  • 19
  • 86
  • 108
  • 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 Apr 12 '10 at 19:54
  • 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 Apr 13 '10 at 08:56
1

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
  • 126
  • 2