You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CUDA 11.8下CUPTI callback_profiling单命令编译报错求助

CUPTI callback_profiling示例编译链接错误修复

在Ubuntu系统CUDA 11.8环境中,编译/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling路径下的CUPTI callback_profiling示例代码时,因Makefile权限问题自行编写nvcc编译命令,但出现链接错误。

原编译命令

nvcc --generate-line-info callback_profiling.cu -o callback_profiling -lnvperf_host -lnvperf_target -lcuda -lcupti -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/profilerhost_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/c_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../../include -L /usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/src/profilerhost_util

链接错误信息

/usr/bin/ld: /tmp/tmpxft_00005e71_00000000-11_callback_profiling.o: in function `setupProfiling(ProfilingData_t*)':
tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0xe48): undefined reference to `NV::Metric::Config::GetConfigImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned char const*)'
/usr/bin/ld: tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0xed3): undefined reference to `NV::Metric::Config::GetCounterDataPrefixImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned char const*)'
/usr/bin/ld: /tmp/tmpxft_00005e71_00000000-11_callback_profiling.o: in function `main':
tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0x2751): undefined reference to `NV::Metric::Eval::PrintMetricValues(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned char const*)'
collect2: error: ld returned 1 exit status

正确的单命令编译方式

错误源于未链接profilerhost_util库(包含报错中未定义的NV::Metric相关函数),且未指定匹配std::__cxx11的C++标准。正确命令如下:

nvcc --generate-line-info -std=c++11 callback_profiling.cu -o callback_profiling -lnvperf_host -lnvperf_target -lcuda -lcupti -lprofilerhost_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/profilerhost_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/c_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../../include -L/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/src/profilerhost_util

关键修改说明

  • 添加-std=c++11:确保编译器使用兼容std::__cxx11命名空间的C++标准,避免字符串相关的ABI不匹配
  • 添加-lprofilerhost_util:链接包含NV::Metric系列函数的依赖库,解决未定义引用问题
  • 调整-L参数格式:移除路径前的空格(可选,符合Linux编译命令的常规写法)

内容的提问来源于stack exchange,提问作者BoringSession

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 22:40:31