标签: vc90

C 链接函数无法返回 C++ 类 - 由我的方法的内容导致的错误

我正在导出一个可以从非托管代码调用的方法,但该函数本身存在于托管 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)

c++ managed-c++ extern linkage vc90

5
推荐指数
1
解决办法
4845
查看次数

如何使用正确分发的发行pdb文件构建Qt5

我想在调试发布模式下从具有PDB文件的源构建Qt5 ,但是我遇到两个问题:

  1. 没有生成发布的PDB文件(是解决方案),

  2. 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包含DLLLIB的文件夹,并且仅调试PDB文件(发布PDB文件除外)。Qt生成脚本没有复制发布的PDB文件,就像复制调试PDB文件一样。释放创建的PDB文件,并位于其中的模块中。

有谁知道如何解决这个问题?

PS:作为我自己的解决方案,我想从每个模块文件夹中复制所有* .pdb文件,但我认为这种情况最糟,首先,我将尝试找到更多的人为解决方案。

PSS:Qt4没有这种行为,我们也没有问题。

P3S:这是Qt 类似的bug

谢谢,最好的问候!


环境:

版本:Qt 5.4.1

系统:Win 8.1

工具集:MSVS2008(vc9)


有用的链接:

  1. qmake变量参考
  2. 如何也为Qt库的发行版创建.pdb文件
  3. 所以

release build vc90 pdb qt5

3
推荐指数
1
解决办法
2272
查看次数

标签 统计

vc90 ×2

build ×1

c++ ×1

extern ×1

linkage ×1

managed-c++ ×1

pdb ×1

qt5 ×1

release ×1