我正在导出一个可以从非托管代码调用的方法,但该函数本身存在于托管 C++ 项目中。以下代码导致编译器错误:
error C2526: 'System::Collections::Generic::IEnumerator<T>::Current::get' : C linkage function cannot return C++ class 'System::Collections::Generic::KeyValuePair<TKey,TValue>'
error C2526: 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::GetEnumerator' : C linkage function cannot return C++ class 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::Enumerator'
Run Code Online (Sandbox Code Playgroud)
extern "C"
__declspec( dllexport )
bool MyMethod(std::string &name, std::string &path, std::map<std::string, std::string> &mymap)
{
System::Collections::Generic::Dictionary<System::String ^, System::String^> _mgdMap = gcnew System::Collections::Generic::Dictionary<System::String ^, System::String ^>();
// Blah blah processing
}
Run Code Online (Sandbox Code Playgroud)
稍微研究一下这个错误,这个问题通常与标记为“extern“C”的方法的定义有关。那么为什么它会关心方法内部发生的事情呢?
如果我注释掉 Dictionary 初始化,或者将它切换到 HashTable,一切都会很好地编译。
下面的方法也适用 - 如果不是在本地定义字典,我通过在方法中初始化它来避免局部变量。
bool status = CallAnotherMethod(ConvertToDictionary(mymap));
Run Code Online (Sandbox Code Playgroud)
其中 ConvertToDictionary 被声明为
System::Collections::Generic::Dictionary<System::String ^, System::String ^>^ ConvertToDictionary(std::map<std::string, std::string> &map)
{
} …Run Code Online (Sandbox Code Playgroud) 我想在调试和发布模式下从具有PDB文件的源构建Qt5 ,但是我遇到两个问题:
没有生成发布的PDB文件(这是解决方案),
qt生成系统没有将发布的PDB文件部署到给定的生成prefix文件夹,就像在之后的调试版本中一样nmake.exe install。
这是示例:
> configure -confirm-license -debug-and-release -opensource -shared -platform win32-msvc2008 -prefix x86 -mp -no-opengl -nomake examples
> nmake.exe
> nmake.exe install
Run Code Online (Sandbox Code Playgroud)
构建完成后,我有了qtbase\bin\x86\x86\bin包含DLL,LIB的文件夹,并且仅调试PDB文件(发布PDB文件除外)。Qt生成脚本没有复制发布的PDB文件,就像复制调试PDB文件一样。释放创建的PDB文件,并位于其中的模块中。
有谁知道如何解决这个问题?
PS:作为我自己的解决方案,我想从每个模块文件夹中复制所有* .pdb文件,但我认为这种情况最糟,首先,我将尝试找到更多的人为解决方案。
PSS:Qt4没有这种行为,我们也没有问题。
P3S:这是Qt 类似的bug。
谢谢,最好的问候!
环境:
版本:Qt 5.4.1
系统:Win 8.1
工具集:MSVS2008(vc9)
有用的链接: