【发布时间】:2014-06-03 14:31:18
【问题描述】:
我正在尝试配置 Eclipse,以便它在一个项目中编译一个共享库并在另一个项目中使用它。
问题是,使用 Eclipse 的 CUDA 插件只能选择一种可执行的生成项目类型。
所以我想做的是创建这样一个项目并修改该工具链,以使 Eclipse 除了nvcc 之外不执行任何操作。
如您所见,编译库不是问题:
18:27:25 **** Incremental Build of configuration Default for project cudamath ****
make all
Building file: ../test.cu
Invoking: CUDA NVCC Compiler
nvcc --shared -Xcompiler -fPIC -o "cu_test.o" "../test.cu" && \
echo -n 'cu_test.d' ./ > 'cu_test.d' && \
nvcc -M "../test.cu" >> 'cu_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../test.cu
问题是 Eclipse 然后调用g++ 这是我要切断的工具链的那一步:
Building target: cudamath
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cudamath" ./cu_test.o -lcuda -lcublas -lcudart
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'cudamath' failed
make: *** [cudamath] Error 1
有什么办法可以做到这一点吗?我一直在浏览我的项目设置,但似乎找不到我要找的东西。
【问题讨论】:
-
“CUDA Toolkit”工具链有 2 个工具 - 编译器和链接器。两人都在幕后打电话给 NVCC。
-
嗯.. 到目前为止,我的解决方案是修改
nvcc的标志,以便为我创建一个libLibName.so。为避免“工具链错误”,我刚刚在另一个文件中添加了int main();。这样会创建一个无用的可执行文件,但至少它可以工作。 -
您可以尝试使用 CUDA Toolkit 工具链创建一个新的“共享库”项目吗?