views:

101

answers:

2

I'm trying to compile my CUDA project with CMake 2.8.2. My SDK is located in "/Developed/GPU Computing/" (OSX). The problem is the whitespace in the path, thus CMake doesn't find the libs.

I tried: link_libraries("-L${CUDA_SDK_ROOT_DIR}/lib -lcutil")

Result: i686-apple-darwin10-g++-4.2.1: Computing/C/lib: No such file or directory

Does anyone know how to solve this problem? Thanks in advance.

+1  A: 

You should use the target_link_libraries command

target_link_libraries(NameOfProject ${CUDA_SDK_LIBRARIES})

Make sure that CUDA_SDK_LIBRARIES points to the full path of the cuda libraries.

RobertJMaynard
A: 
    project(VolumeRender)
cmake_minimum_required(VERSION 2.8)
find_package(CUDA)
find_package(GLUT)
find_package(OpenGL)

IF (WIN32)
    FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
        $ENV{PROGRAMFILES}/GLEW/include
        ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
        DOC "The directory where GL/glew.h resides")
    FIND_LIBRARY( GLEW_LIBRARY
        NAMES glew GLEW glew32 glew32s
        PATHS
        $ENV{PROGRAMFILES}/GLEW/lib
        ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
        ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
        DOC "The GLEW library")
ELSE (WIN32)
    FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
        /usr/include
        /usr/local/include
        /sw/include
        /opt/local/include
        DOC "The directory where GL/glew.h resides")
    FIND_LIBRARY( GLEW_LIBRARY
        NAMES GLEW glew
        PATHS
        /usr/lib64
        /usr/lib
        /usr/local/lib64
        /usr/local/lib
        /sw/lib
        /opt/local/lib
        DOC "The GLEW library")
ENDIF (WIN32)

IF (GLEW_INCLUDE_PATH)
    SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ELSE (GLEW_INCLUDE_PATH)
    SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ENDIF (GLEW_INCLUDE_PATH)

MARK_AS_ADVANCED( GLEW_FOUND )

FIND_PATH( SHRUTIL_INCLUDE_PATH shrUtils.h
        ${CUDA_SDK_ROOT_DIR}/../shared/inc
        DOC "The directory where shrutil.h resides")
FIND_LIBRARY( SHRUTIL_LIBRARY
        NAMES SHRUTIL shrutil_i386
        PATHS
        ${CUDA_SDK_ROOT_DIR}/../shared/lib
        DOC "The SHRUTIL library")

FIND_LIBRARY( CUTIL_LIBRARY
        NAMES CUTIL cutil_i386
        PATHS
        ${CUDA_SDK_ROOT_DIR}/lib
        DOC "The CUTIL library")


include(FindCUDA)
set(CORELIBS 
    ${GLUT_LIBRARY} 
    ${OPENGL_LIBRARY}
    ${GLEW_LIBRARY} 
    ${CUDA_SDK_LIBRARIES} 
    ${SHRUTIL_LIBRARY} 
    ${CUTIL_LIBRARY} 
    m)

set(CUDA_64_BIT_DEVICE_CODE OFF) 
set(CMAKE_CXX_FLAGS "-g -Wall -m32")
set(CUDA_VERBOSE_BUILD ON)

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

link_libraries(${CORELIBS})

include_directories(
    ${CUDA_SDK_ROOT_DIR}/common/inc
    ${CUDA_SDK_ROOT_DIR}/../shared/inc
    ${CMAKE_CURRENT_SOURCE_DIR}
)

cuda_add_executable(
    volumeRender 
    volumeRender.cpp 
    volumeRender_kernel.cu
)

With the script above, it compiles/links fine. The problem is XCode project generation. It generates a XCode project, but if I try to build and run the project from within XCode, it again cannot find any library. Does anyone know why XCode can't find the libraries?

baal666
Does it fail to find the library if you use the makefile or codeblocks generator?
RobertJMaynard
No it doesn't fail. It only fails for XCode
baal666