Error in running sample programs, because "undefined reference to `cudaFree'"
PriscillaJCorn opened this issue · comments
Hi guys,
According to the README.md file in libkineto/sample_programs/, I have run the script step by step. kplay-cu.o has been generated after executing the ./build-cu.sh script without reporting an error. However, when I run the ./build.sh script, there occurs a trouble showing that
In file included from /usr/local/include/kineto/IActivityProfiler.h:16,
from /usr/local/include/kineto/ActivityProfilerInterface.h:18,
from /usr/local/include/kineto/libkineto.h:24,
from kineto_playground.cpp:14:
/usr/local/include/kineto/GenericTraceActivity.h: In member function ‘virtual const string libkineto::GenericTraceActivity::getMetadataValue(const string&) const’:
/usr/local/include/kineto/GenericTraceActivity.h:104:9: warning: init-statement in selection statements only available with ‘-std=c++17’ or ‘-std=gnu++17’
104 | if (auto it = metadataMap_.find(key); it != metadataMap_.end()) {
| ^~~~
/usr/local/include/kineto/GenericTraceActivity.h: In member function ‘virtual const string libkineto::GenericTraceActivity::metadataJson() const’:
/usr/local/include/kineto/GenericTraceActivity.h:113:22: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
113 | for (const auto& [key, val] : metadataMap_) {
/usr/bin/ld: kplay_cu.o: in function `kineto::warmup()':
tmpxft_001b9c0e_00000000-6_kineto_playground.cudafe1.cpp:(.text+0x81): undefined reference to `cudaFree'
/usr/bin/ld: kplay_cu.o: in function `kineto::basicMemcpyToDevice()':
tmpxft_001b9c0e_00000000-6_kineto_playground.cudafe1.cpp:(.text+0x146): undefined reference to `cudaMemcpy'
/usr/bin/ld: kplay_cu.o: in function `kineto::basicMemcpyFromDevice()':
tmpxft_001b9c0e_00000000-6_kineto_playground.cudafe1.cpp:(.text+0x1a5): undefined reference to `cudaMemcpy'
/usr/bin/ld: tmpxft_001b9c0e_00000000-6_kineto_playground.cudafe1.cpp:(.text+0x1f5): undefined reference to `cudaFree'
... ...
collect2: error: ld returned 1 exit status
It seems that someting wrong when I reference the CUDA library file by using the following arguments
g++ \
-g3 \
-O0 \
kineto_playground.cpp \
-o main \
-I /usr/local/cuda/include \
-I /mnt/data/PriscillaJCorn/software/fmt-10.2.1/include/ \
-I /usr/local/include/kineto \
-L /usr/local/lib \
-L /usr/local/cuda/lib64 \
-l pthread \
-l cuda \
-l cudart \
/usr/local/lib/libkineto.a \
kplay_cu.o
Well, I have check the path of CUDA library files and all are correct. Could somebody tell me how to solve this question? Thanks :)
Fine. I have solved this problem by replacing "-lcudart" with "/usr/local/cuda-11.8/targets/x86_64-linux/lib/libcudart.so". You can close this question.