将Openssl库(调用约定_cdecl)与dll链接(调用约定_stdcall) [英] Linking Openssl library(calling convention _cdecl) with a dll(calling convention _stdcall)

查看:141
本文介绍了将Openssl库(调用约定_cdecl)与dll链接(调用约定_stdcall)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我将openssl库(openssl.lib)链接到dll。当我构建这个DLL时,我发现很少有链接器错误。我调试并发现链接器错误是因为调用了dll的约定。我的dll使用_stdcall调用约定,而openssl使用_cdecl
调用约定。我不能改变我的dll的调用约定,因为它是现有解决方案的一部分。所以我试图将openssl的调用约定更改为_stdcall。但我不能这样做,最终导致了以下构建错误。



\crypto \\\\ui_openssl.c(591):错误C2440:'function ':无法从'void(__ stdcall *)(int)'转换为'void(__ cdecl *)(int)'。\ crypto \\\\ui_openssl.c(591):警告C4024:'signal':不同正式和实际参数2的类型。\\\ crypto \\\\ui_openssl.c(591)
:错误C2440:'=':无法从'void(__ cdecl *)(int)'转换为'void (__stdcall *)(int)'。\ crypto \\\\ui_openssl.c(592):错误C2440:'function':无法从'void(__ stdcall *)(int)'转换为'void(__ cdecl * )(int)'
$


导致构建错误的代码行是:



static void pushsig(无效)



#ifndef OPENSSL_SYS_WIN32

    int i;

#endif

#ifdef SIGACTION

  struct sigaction sa;



  memset(& sa,0,sizeof sa);

  sa.sa_handler = recsig;

#endif



#ifdef OPENSSL_SYS_WIN32

  savsig [SIGABRT] =信号(SIGABRT,recsig); // **第591行**

  savsig [SIGFPE] =信号(SIGFPE,recsig);    // **第592行**
b $ b  savsig [SIGILL] = signal(SIGILL,recsig);

如何使用_stdcall构建openssl库( / Gz)召集会议?或者还有其他解决方案吗?
b
$
注意:信号是一个Windows API(调用约定是_cdecl)。请参考此链接https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx



谢谢,

Sathish 。

Hi,

I am linking openssl library(openssl.lib) to an dll. When I build this dll, I found few linker errors. I debugged and found that linker errors are because of calling convention of dll. My dll is using _stdcall calling convention whereas openssl is using _cdecl calling convention. I can't change the calling convention of my dll since it is part of existing solution. So I tried to change the calling convention of openssl to _stdcall. But I could not do, it ended up in following build errors.

\crypto\ui\ui_openssl.c(591) : error C2440: 'function' : cannot convert from 'void (__stdcall *)(int)' to 'void (__cdecl *)(int)' .\crypto\ui\ui_openssl.c(591) : warning C4024: 'signal' : different types for formal and actual parameter 2 .\crypto\ui\ui_openssl.c(591) : error C2440: '=' : cannot convert from 'void (__cdecl *)(int)' to 'void (__stdcall *)(int)' .\crypto\ui\ui_openssl.c(592) : error C2440: 'function' : cannot convert from 'void (__stdcall *)(int)' to 'void (__cdecl *)(int)'

Lines of code causing the build errors are:

static void pushsig(void)

#ifndef OPENSSL_SYS_WIN32
   int i;
#endif
#ifdef SIGACTION
 struct sigaction sa;

 memset(&sa,0,sizeof sa);
 sa.sa_handler=recsig;
#endif

#ifdef OPENSSL_SYS_WIN32
 savsig[SIGABRT]=signal(SIGABRT,recsig); // **line 591**
 savsig[SIGFPE]=signal(SIGFPE,recsig);   // **line 592**
 savsig[SIGILL]=signal(SIGILL,recsig);
How can I build the openssl library with _stdcall(/Gz) calling convention? Or is there any other solution to this ?

Note : signal is a windows API(calling convention is _cdecl). Please refer this link https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx

Thanks,
Sathish.

推荐答案

处理此问题的一种方法是将dll代码的默认编译器调用约定保留为__cdecl。 然后,在代码的函数的声明/定义中指定它们使用__stdcall。  这将消除冲突
并避免更改openssl库的呼叫约定的需要




One way to deal with this is to leave the default compiler calling convention for your dll code as __cdecl.  Then, specify in the declarations/definitions of your code's functions that they use __stdcall.   That would eliminate the conflict and avoid the need to change the openssl library's calling convention



这篇关于将Openssl库(调用约定_cdecl)与dll链接(调用约定_stdcall)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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