Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如果我尝试在同一个项目中使用stl矢量和CUDA推力矢量,为什么会出现链接错误?_C++_Stl_Cuda_Thrust - Fatal编程技术网

C++ 如果我尝试在同一个项目中使用stl矢量和CUDA推力矢量,为什么会出现链接错误?

C++ 如果我尝试在同一个项目中使用stl矢量和CUDA推力矢量,为什么会出现链接错误?,c++,stl,cuda,thrust,C++,Stl,Cuda,Thrust,如果我尝试在同一个项目中使用stl矢量和CUDA推力矢量,为什么会出现链接错误 文件1.h #include <vector> using namespace std; class A{ public: A(); vector<int> vec; //.... }; #包括 使用名称空间std; 甲级{ 公众: A(); 向量向量机; //.... }; File2.cu #include <thrust/device_vector.h>

如果我尝试在同一个项目中使用stl矢量和CUDA推力矢量,为什么会出现链接错误

文件1.h

#include <vector>
using namespace std;
class A{
public:
    A();
    vector<int> vec;
//....
};
#包括
使用名称空间std;
甲级{
公众:
A();
向量向量机;
//....
};
File2.cu

#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
void ComputeDer(){
thrust::device_vector<int> Dh(4);
thrust::host_vector<int> H(4);//only host_vector can compile.
}
#包括
#包括
void计算程序(){
推力:装置_矢量Dh(4);
host::host_vector H(4);//只有host_vector可以编译。
}
如果我注释掉其中一个向量声明,则可以编译代码,但如果两者都存在,则会出现以下错误:

1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in ComputeDer.cu.obj
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in ComputeDer.cu.obj
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in ComputeDer.cu.obj
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in ComputeDer.cu.obj
1>msvcprtd.lib(MSVCP90D.dll):错误LNK2005:“public:\uu thiscall std::basic\u string::~basic\u string(void)”(??1?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@QAE@XZ)已在ComputeDer.cu.obj中定义
1> msvcprtd.lib(MSVCP90D.dll):错误LNK2005:“public:u thiscall std::basic_string::basic_string(char const*)”(??0?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@QAE@PBD@Z) 已在ComputeDer.cu.obj中定义
1> msvcprtd.lib(MSVCP90D.dll):错误LNK2005:“public:u thiscall std::basic_string::basic_string(类std::basic_string const&)”(?0?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@QAE@ABV01@@Z) 已在ComputeDer.cu.obj中定义
1> msvcprtd.lib(MSVCP90D.dll):错误LNK2005:“public:char const*u thiscall std::basic_string::c_str(void)const”(?c_str@?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@QBEPBDXZ)已在ComputeDer.cu.obj中定义

有人能告诉我一些想法吗?

最有可能的问题是

using namespace std;

使用它并不是一种好的做法,但如果您选择使用它,至少可以使用它将其放入.cpp文件中,而不是头文件中。通过将其放入头文件,您可以将其外推到包括该头文件在内的所有文件。

谢谢您的回答。但是我在File1.h中尝试了“std::vector vec;”,问题仍然存在。@user3092410您是否尝试使用名称空间std;完全来自所有头,或者只是将向量作为sd::vector寻址,但仍然使用名称空间std;某个地方的指令?谢谢,但我已经删除了整个项目中的所有“使用命名空间std”。它无法解决问题。编译器设置有问题吗?因为我觉得其他人的项目没问题。你能显示链接器选项吗?我不熟悉Cuda。
ComputeDer.cu
是另一个源文件吗?我只添加了以下两个库:cudart.lib和cuda.lib。其他是VS 2008Ok的默认设置。这些是调试库版本吗?从错误中,我了解到您正在
Debug
配置中构建文件。因此,所有链接库都需要是调试版本。您不能混合使用库的发行版和调试版。以下是部分:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\lib\Win32\I在调试模式下编译,这只是库所在的路径。问题是文件夹是否有调试库版本。另外,尝试在
发布版
配置中构建项目,看看问题是否重现。