C ++中未解析的外部程序:Visual C ++ Mangles方法签名与dll中的mangled方法不同 [英] Unresolved Externals in C++: Visual C++ mangles method signature differently from mangled method in dll

查看:182
本文介绍了C ++中未解析的外部程序:Visual C ++ Mangles方法签名与dll中的mangled方法不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2012(托管C ++)在第三方SDK与C#编写的系统之间建立桥梁。我已经成功地包装并从SDK中消耗了几个功能。除了一个,这只会导致未解决的外部错误。

I'm using Visual Studio 2012, managed C++, to make a bridge between a third party SDK and our system which is written in C#. I have succesfully wrapped and consumed several functions from said SDK. Except one, which only result in a Unresolved External Error.

SDK的头文件定义了函数的签名:

The SDK's header file defines the function's signature:

#if defined WIN32
    #if defined BUILD_ADS_SHARED_LIB
        #define ADS_LINK_SPEC __declspec (dllexport)
        #define ADS_CALLING_CONVENTION __stdcall
    #elif defined USE_ADS_SHARED_LIB
        #define ADS_LINK_SPEC __declspec (dllimport)
        #define ADS_CALLING_CONVENTION __stdcall
    #else
        #define ADS_LINK_SPEC
        #define ADS_CALLING_CONVENTION
    #endif
#else
    #define ADS_LINK_SPEC
    #define ADS_CALLING_CONVENTION
#endif

DatabaseResult ADS_LINK_SPEC ADS_CALLING_CONVENTION
createDatabase(
    const Settings& settings, Artec::SdkDatabase::iDatabase *& instance);

错误说:

Error   10  error LNK2028: unresolved token (0A000089) "enum Artec::SdkDatabase::DatabaseResult __cdecl Artec::SdkDatabase::createDatabase(class Artec::SdkDatabase::Settings const &,class Artec::SdkDatabase::iDatabase * &)" (?createDatabase@SdkDatabase@Artec@@$$FYA?AW4DatabaseResult@12@ABVSettings@12@AAPAViDatabase@12@@Z) referenced in function "private: static enum Artec::SdkDatabase::DatabaseResult __clrcall Broadway3dWrapper::Broadway3dWrapper::GetConn(wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,char const *,class Artec::SdkDatabase::iDatabase * &)" (?GetConn@Broadway3dWrapper@1@$$FCM?AW4DatabaseResult@SdkDatabase@Artec@@PB_W000PBDAAPAViDatabase@34@@Z) C:\bioap\tfs\Identitum\Dev\src\BA.Identitum.Devices.Broadway3d\Broadway3dWrapper.obj    BA.Identitum.Devices.Brodway3D

所以它正在寻找被破坏的名字:

So it's looking for the mangled name:

?createDatabase@SdkDatabase@Artec@@$$FYA?AW4DatabaseResult@12@ABVSettings@12@AAPAViDatabase@12@@Z

在引用的dll上做一个dumpbin,我发现实际上有一个类似导出的函数,事情就是这个名字有点不同:

Making a little dumpbin on the referenced dll, I found there is in fact a function called like that exported, thing is the name is mangled slightly different:

?createDatabase@SdkDatabase@Artec@@YG?AW4DatabaseResult@12@ABVSettings@12@AAPAViDatabase@12@@Z

任何人都可以帮助我吗?我不能联系SDK供应商,我完全迷失在这里。

Can anyone help me here? I cannot contact the SDK vendor, and I'm completely lost here.

推荐答案

这两者之间的区别在于调用约定

The difference between those two lies in the calling convention section.

createDatabase @ SdkDatabase @ Artec @@ YG?AW4DatabaseResult @ 12 @ ABVSettings @ 12 @ AAPAViDatabase @ 12 @@ Z 是stdcall: enum Artec :: SdkDatabase :: DatabaseResult __stdcall Artec :: SdkDatabase :: createDatabase(class Artec :: SdkDatabase :: Settings const&,class Artec :: SdkDatabase :: iDatabase * &)

createDatabase@SdkDatabase@Artec@@YG?AW4DatabaseResult@12@ABVSettings@12@AAPAViDatabase@12@@Z is stdcall: enum Artec::SdkDatabase::DatabaseResult __stdcall Artec::SdkDatabase::createDatabase(class Artec::SdkDatabase::Settings const &,class Artec::SdkDatabase::iDatabase * &)

我使用的demangler 不明白?createDatabase @ SdkDatabase @ Artec @@ $$ FYA?AW4DatabaseResult @ 12 @ ABVSettings @ 12 @ AAPAViDatabase @ 12 @@ Z ,但它们不同的部分( @@ $$ FYA? vs @@ YG?)是调用约定(如果我将 YG 更改为 YF ,则调用约定将更改,无其他操作)。

The demangler I used does not understand ?createDatabase@SdkDatabase@Artec@@$$FYA?AW4DatabaseResult@12@ABVSettings@12@AAPAViDatabase@12@@Z, but the part where they differ (@@$$FYA? vs @@YG?) is the calling convention (if I change YG to YF, the calling convention changes and nothing else does).

更改您的声明的功能到 return-type __stdcall function-name [(argument-list)]

Change your declaration of the function to return-type __stdcall function-name[(argument-list)].

头文件,您是否明确地或在编译器命令行上是否有 #define USE_ADS_SHARED_LIB ?您是否定位32位窗口?

When you included the header file, did you #define USE_ADS_SHARED_LIB explicitly or on the compiler command line? Are you targeting 32 bit windows?

这篇关于C ++中未解析的外部程序:Visual C ++ Mangles方法签名与dll中的mangled方法不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆