我正在尝试配置 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
我有办法做到这一点吗?我一直在浏览我的项目设置,但我似乎找不到我要找的东西。
最佳答案
这是我使用 Nsight Eclipse Edition 所做的:
- 文件...新的 CUDA C/C++ 项目
- 在下一个对话框中,选择 Shared Library...Empty Project,并为项目命名(假设它是
teSTLib
) - 完成该向导/对话框。在左侧的项目资源管理器中新建了一个
teSTLib
项目 - 在左侧的项目资源管理器中,右键单击项目名称并为您的源文件创建一个新文件夹
- 打开该文件夹并创建新的源文件。为此,我使用 CUDA bitreverse"template"选择了一个 CUDA C/C++ 源文件。这将创建一个新的源文件,其中包含 bitreverse 代码。
- 将源文件中的
int main() {
更改为int myfunc(){
- 保存源文件并构建项目。新的
libteSTLib.so
构建成功。
关于c++ - Eclipse:编辑工具链(删除构建步骤以创建 CUDA 共享库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24017890/