7

I have installed CUDA on my system, but seems like its files are not being found by libraries that depend on it. What should I append to my .bashrc in order for both GCC and Clang to look on the directories /usr/local/cuda/include and /usr/local/cuda/lib ?

4 Answers 4

6

Both the GCC and Clang drivers respect the following environment variables:

export C_INCLUDE_PATH=/usr/local/cuda/include
export CPLUS_INCLUDE_PATH=/usr/local/cuda/include
export LIBRARY_PATH=/usr/local/cuda/lib

Check the manuals.

1

You have to do it:

gcc -I/path_of_include_files -L/path_of_load_libraries_files 

NOTE: you can have some -I and some -L such as :

gcc -I. -L. -I../include -L../libs
1

Both gcc and clang respect some environment variables that can help achieve what you want. Try adding these to your ~/.bashrc:

export CFLAGS="-I /usr/local/cuda/include"
export LDFLAGS="-L /usr/local/cuda/lib"

However this is usually not done on a global level - different projects need different includes and libs so best to configure the custom include and lib directories per-project in your Makefile or using ./configure.

1
  • 3
    This answer is misleading. CFLAGS and LDFLAGS aren't environment variables related to GCC or Clang. These are make variables merely respected by convention.
    – alecov
    Oct 28, 2018 at 20:43
1

If you have a working pkgconfig, then you can use it to add appropriate GCC flags:

$(pkg-config --cflags cuda) $(pkg-config --libs cuda)

For example:

gcc filename.c -o outputfile $(pkg-config --cflags --libs cuda) 

In a Makefile, that would normally look like:

CFLAGS += $(pkg-config --cflags cuda)
LIBS += $(pkg-config --libs cuda)
1
  • for this you will need the pkg-config utility installed, which is present in most of unix like oses Jul 23, 2023 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .