21

How can I force gcc to look in /usr/cuda/local/include for cuda_runtime.h?

I'm attempting to compile a CUDA application with a C wrapper. I'm running Ubuntu 10.04.

I've successfully compiled my CUDA application into a .so with the following command:

nvcc -arch=sm_11 -o libtest.so --shared -Xcompiler -fPIC main.cu

When I try and compile my c wrapper file with the following command:

gcc -std=c99 -o main -L. -ltest main.c

I receive the error:

error: cuda_runtime.h: No such file or directory

I've verified that cuda_runtime.h is in fact present in /usr/local/cuda/include

skrieder
  • 379
  • 1
  • 2
  • 8
  • 4
    I assume you mean /usr/local/cuda/include. Did you try adding a -I switch to your gcc command line? For example: gcc -std=c99 -I/usr/local/cuda/include -o main -L. -ltest main.c – Robert Crovella Oct 31 '12 at 21:22
  • 1
    If you wouldn't mind, please post it as an answer to your question. Then accept it or I will upvote the answer. Thank you. – Robert Crovella Oct 31 '12 at 21:38
  • Is there any option to make it work without adding -l? A library gives me this error – Keloo Sep 06 '16 at 10:45

5 Answers5

16

If you are using CMake

find_package(CUDA  REQUIRED)
include_directories("${CUDA_INCLUDE_DIRS}")
Alex Punnen
  • 5,287
  • 3
  • 59
  • 71
12

Using an -I switch allowed gcc to find the cuda_runtime.h file:

gcc -std=c99 -I/usr/local/cuda/include -o main -L. -ltest main.c
talonmies
  • 70,661
  • 34
  • 192
  • 269
skrieder
  • 379
  • 1
  • 2
  • 8
10

We were using CMake but it still wasn't able to find the header files (maybe it is the CMake version that couldn't find the directory ./targets/x86_64-linux/include or because we have multiple CUDA versions). Setting CPATH and LD_LIBRARY_PATH fixed it for us:

export CPATH=/usr/local/cuda-10.1/targets/x86_64-linux/include:$CPATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/targets/x86_64-linux/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-10.1/bin:$PATH
Yamaneko
  • 3,433
  • 2
  • 38
  • 57
0

Add -isystem /usr/local/cuda-8.0/include to CXX_INCLUDES in flags.make file.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
Vidhu
  • 1
  • 1
0

Using modern CMake https://cliutils.gitlab.io/modern-cmake/chapters/packages/CUDA.html - CUDA has become a CMake language just like CXX:

check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
    enable_language(CUDA)

    # to tell your code it was found via #ifdef USE_CUDA:
    add_definitions(-DUSE_CUDA)    

    include_directories("${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
endif()

and after definition of executable or library don't forget cuda arch version(s)

set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES "35;50;72")
DomTomCat
  • 8,189
  • 1
  • 49
  • 64