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
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.
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
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.
-
3This answer is misleading.
CFLAGSandLDFLAGSaren't environment variables related to GCC or Clang. These are make variables merely respected by convention.alecov– alecov2018-10-28 20:43:43 +00:00Commented Oct 28, 2018 at 20:43
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)
-
for this you will need the pkg-config utility installed, which is present in most of unix like osestheFooMonk– theFooMonk2023-07-23 10:05:27 +00:00Commented Jul 23, 2023 at 10:05