簡體   English   中英

Visual Studio C++ 編譯器嘗試編譯 CUDA C/C++ 文件

[英]Visual Studio C++ compiler tries to compile CUDA C/C++ files

我正在嘗試制作一個我一直在使用 CUDA 的項目。 目前它有四個構建配置,兩個(發布和調試)定義了一個編譯器符號,因此它使用 CUDA 進行編譯,另外兩個(發布和調試)將其定向到 CPU 代碼。

這是 main.cpp 的簡短版本:

#ifdef CUDA
#include "CUDACode.cu"
#else
#include "CPUCode.h"
#endif

int main() {
    functionDefinedinBothHeaders(params);
}

但由於某種原因,NVCC 可以正常運行並編譯它,但隨后 C++ 編譯器嘗試編譯它,這會導致許多錯誤,我已經設法使用#ifdef __NVCC__語句規避了這些錯誤,但現在我遇到了 main.cpp 必須使用某些東西的問題從 header 所以我把它放在#ifdef __NVCC__語句之外,現在我得到 linker 錯誤,因為它們被定義了兩次,因為 NVCC 編譯它並且 ZF6F87C9FDCF8B3C3F07F93F1EE81 也一樣

error LNK2005: "class boost::random::mersenne_twister_engine<unsigned int,32,351,175,19,3433795303,11,4294967295,7,834054912,15,4293197824,17,1812433253> generator" (?generator@@3V?$mersenne_twister_engine@I$0CA@$0BFP@$0KP@$0BD@$0MMKLIOOH@$0L@$0PPPPPPPP@$06$0DBLGKLAA@$0P@$0PPOFAAAA@$0BB@$0GMAHIJGF@@random@boost@@A) already defined in CUDAStateCalc.cu.obj

.cu 文件設置為 CUDA C/C++ 代碼。 我該如何阻止它這樣做? 有沒有比我正在做的更好的方法?

Robert Crovella answered my question in the comments, what I needed to do was have a header function that was included in main.cpp and CUDACode.cu and contained the function prototype for functionDefinedinBothHeaders but CUDACode.cu defined it

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM