Compile wxWidgets source using __stdcall instead of __cdecl on Windows
-
- Filthy Rich wx Solver
- Posts: 221
- Joined: Fri Jan 08, 2021 8:19 am
Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Hi
We have all our source code compiled using _stdcall calling convention. We are planning to implement wxWidgets dll dialog code in our source. This requires wxWidgets dependent libraries to be compiled using stdcall calling convention instead of _cdecl calling convension.
When we tried to compile the source on windows using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86", it is creating the dependent libraries using cdecl calling convention (by default) on windows and we are not able to link them with our wxWidgets dll code (compiled using stdcall). It is giving linker errors as our code is compiled using stdcall and wxWidgets src is compiled in cdecl.
What is best approach to compile the wxWidgets code using stdcall convention. Is there a easy way to use the stdcalls with wxWidgets code?
I tried compiling the source using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86 CPPFLAGS="/Gz"" but it is givining linker error whilst compiling the code.
did anyone try this? Need some quick help. Thanks in advance.
Regards
Sree
We have all our source code compiled using _stdcall calling convention. We are planning to implement wxWidgets dll dialog code in our source. This requires wxWidgets dependent libraries to be compiled using stdcall calling convention instead of _cdecl calling convension.
When we tried to compile the source on windows using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86", it is creating the dependent libraries using cdecl calling convention (by default) on windows and we are not able to link them with our wxWidgets dll code (compiled using stdcall). It is giving linker errors as our code is compiled using stdcall and wxWidgets src is compiled in cdecl.
What is best approach to compile the wxWidgets code using stdcall convention. Is there a easy way to use the stdcalls with wxWidgets code?
I tried compiling the source using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86 CPPFLAGS="/Gz"" but it is givining linker error whilst compiling the code.
did anyone try this? Need some quick help. Thanks in advance.
Regards
Sree
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Hi,
Why do you need to use _cdecl?
Since you are on Windows - did you look at the dll sample?
I myself am using windows and building dll with default wxwidgets build...
Thank you.
Why do you need to use _cdecl?
Since you are on Windows - did you look at the dll sample?
I myself am using windows and building dll with default wxwidgets build...
Thank you.
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Shouldn't it be enough to use _stdcall only for the exported functions of your DLL?
Use the source, Luke!
-
- Filthy Rich wx Solver
- Posts: 221
- Joined: Fri Jan 08, 2021 8:19 am
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Why do you need to use _cdecl?
Sree>> When we compile the wxWidget source using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86" on windows, it is using _cdecl by default and not _stdcall. So how do we compile the source using _stdcall calling convention?
Since you are on Windows - did you look at the dll sample?
Sree>> Yes, the dll sample is compiled using _cdecl and not _stdcall. Since our dependent code and libraries are compiled using _stdcall, we also need to compile the dll sample in stdcall and it is giving linker erros as wxWidgets code is compiled using _cdecl.
I myself am using windows and building dll with default wxwidgets build...
Sree>> You might be using _cdecl on windows and hence there is no issue with linking your code. Please cross check.
Thank you for the response.
Sree>> When we compile the wxWidget source using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86" on windows, it is using _cdecl by default and not _stdcall. So how do we compile the source using _stdcall calling convention?
Since you are on Windows - did you look at the dll sample?
Sree>> Yes, the dll sample is compiled using _cdecl and not _stdcall. Since our dependent code and libraries are compiled using _stdcall, we also need to compile the dll sample in stdcall and it is giving linker erros as wxWidgets code is compiled using _cdecl.
I myself am using windows and building dll with default wxwidgets build...
Sree>> You might be using _cdecl on windows and hence there is no issue with linking your code. Please cross check.
Thank you for the response.
-
- Filthy Rich wx Solver
- Posts: 221
- Joined: Fri Jan 08, 2021 8:19 am
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Shouldn't it be enough to use _stdcall only for the exported functions of your DLL?
Sree>> My wxWidget dll code has to link wxWidget libraries (which are compiled using _cdecl) and also our internal dll libraries (which are compiled using _stdcall). So my wxWidget dll code has to be compiled using _stdcall so that it can work with wxWidgets and also our internal code.
This means, I have to compile the wxWidgets source using _stdcall instead of _cdecl. So is there a easy way to do it.
Note: I cannot use "extern __stdcall" for only the calls which are referenced in wxWidgets because my wxwidget dll is linking lot wxWidget libraries and I might end up using extern for all most all of the funtions exported in wxWidgets core libraries. So better approach would be to compile wxWidget source using _stdcall (I assume?).
Please suggest the best approach. Thanks
Sree>> My wxWidget dll code has to link wxWidget libraries (which are compiled using _cdecl) and also our internal dll libraries (which are compiled using _stdcall). So my wxWidget dll code has to be compiled using _stdcall so that it can work with wxWidgets and also our internal code.
This means, I have to compile the wxWidgets source using _stdcall instead of _cdecl. So is there a easy way to do it.
Note: I cannot use "extern __stdcall" for only the calls which are referenced in wxWidgets because my wxwidget dll is linking lot wxWidget libraries and I might end up using extern for all most all of the funtions exported in wxWidgets core libraries. So better approach would be to compile wxWidget source using _stdcall (I assume?).
Please suggest the best approach. Thanks
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
There is no built-in mechanism, configure switch etc. to change the calling convention. But i'm still not convinced you actually need to change anything, if your app only communicates with the DLL should its exported functions.
But i hardly ever use DLLs, so i don't know too much about this topic.
Maybe try asking on the wx-users Google group. https://groups.google.com/g/wx-users
But i hardly ever use DLLs, so i don't know too much about this topic.
Maybe try asking on the wx-users Google group. https://groups.google.com/g/wx-users
Use the source, Luke!
-
- Filthy Rich wx Solver
- Posts: 221
- Joined: Fri Jan 08, 2021 8:19 am
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Our dll is compiled using stdcall calling convention (i.e. with /Gz compiler flag in visual studio compiler). WxWidget source is by default compiled using cdecl calling convention(i.e with /Gr compiler flag in visual studio). So the linker cannot link the wxWidget libraries when referred from our code which is compiled using cdecl calling convention . It cannot find the exported signatures. I hope you understood the issue.
We get the following errors:
{{{
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class wxString __stdcall wxString::FromAscii(char const *)" (__imp_?FromAscii@wxString@@SG?AV1@PBD@Z) referenced in function "public: __thiscall CustomDialog::CustomDialog(class wxWindow *,int,class wxString const &,class wxPoint const &,class wxSize const &,long)" (??0CustomDialog@@QAE@PAVwxWindow@@HABVwxString@@ABVwxPoint@@ABVwxSize@@J@Z)
1>ui_wx_signon_wrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class wxString __stdcall wxString::FromAscii(char const *)" (__imp_?FromAscii@wxString@@SG?AV1@PBD@Z)
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __stdcall wxMessageBox(class wxString const &,class wxString const &,long,class wxWindow *,int,int)" (__imp_?wxMessageBox@@YGHABVwxString@@0JPAVwxWindow@@HH@Z) referenced in function "protected: virtual void __thiscall CustomDialog::m_sdbSizer1OnOKButtonClick(class wxCommandEvent &)" (?m_sdbSizer1OnOKButtonClick@CustomDialog@@MAEXAAVwxCommandEvent@@@Z)
1>ui_wx_signon_wrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall wxMessageBox(class wxString const &,class wxString const &,long,class wxWindow *,int,int)" (__imp_?wxMessageBox@@YGHABVwxString@@0JPAVwxWindow@@HH@Z)
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class wxString __stdcall operator+(class wxString const &,class wxString const &)" (__imp_??H@YG?AVwxString@@ABV0@0@Z) referenced in function "protected: virtual void __thiscall CustomDialog::m_sdbSizer1OnOKButtonClick(class wxCommandEvent &)" (?m_sdbSizer1OnOKButtonClick@CustomDialog@@MAEXAAVwxCommandEvent@@@Z)
}}}
We get the following errors:
{{{
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class wxString __stdcall wxString::FromAscii(char const *)" (__imp_?FromAscii@wxString@@SG?AV1@PBD@Z) referenced in function "public: __thiscall CustomDialog::CustomDialog(class wxWindow *,int,class wxString const &,class wxPoint const &,class wxSize const &,long)" (??0CustomDialog@@QAE@PAVwxWindow@@HABVwxString@@ABVwxPoint@@ABVwxSize@@J@Z)
1>ui_wx_signon_wrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class wxString __stdcall wxString::FromAscii(char const *)" (__imp_?FromAscii@wxString@@SG?AV1@PBD@Z)
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __stdcall wxMessageBox(class wxString const &,class wxString const &,long,class wxWindow *,int,int)" (__imp_?wxMessageBox@@YGHABVwxString@@0JPAVwxWindow@@HH@Z) referenced in function "protected: virtual void __thiscall CustomDialog::m_sdbSizer1OnOKButtonClick(class wxCommandEvent &)" (?m_sdbSizer1OnOKButtonClick@CustomDialog@@MAEXAAVwxCommandEvent@@@Z)
1>ui_wx_signon_wrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall wxMessageBox(class wxString const &,class wxString const &,long,class wxWindow *,int,int)" (__imp_?wxMessageBox@@YGHABVwxString@@0JPAVwxWindow@@HH@Z)
1>ui_wx_signon.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class wxString __stdcall operator+(class wxString const &,class wxString const &)" (__imp_??H@YG?AVwxString@@ABV0@0@Z) referenced in function "protected: virtual void __thiscall CustomDialog::m_sdbSizer1OnOKButtonClick(class wxCommandEvent &)" (?m_sdbSizer1OnOKButtonClick@CustomDialog@@MAEXAAVwxCommandEvent@@@Z)
}}}
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Disclaimer: I cannot say I really understand the issue (changing the calling convention being a best solution), so I may be missing something.
All wxWidgets classes (e.g., wxString) and functions (e.g., wxSplit) exported from wxWidgets DLLs are declared with WXDLLIMPEXP_<library> macro (e.g., WXDLLIMPEXP_BASE). For example,
or
When building wxWidgets DLL WXDLLIMPEXP_<library> basically expands to WXEXPORT, when linking to wxWidgets it expands to WXIMPORT instead. These are with MSVC set to
Do you mean that you want change the calling convention for this?
All wxWidgets classes (e.g., wxString) and functions (e.g., wxSplit) exported from wxWidgets DLLs are declared with WXDLLIMPEXP_<library> macro (e.g., WXDLLIMPEXP_BASE). For example,
Code: Select all
class WXDLLIMPEXP_BASE wxString
Code: Select all
WXDLLIMPEXP_BASE wxArrayString wxSplit
Code: Select all
#define WXEXPORT __declspec(dllexport)
#define WXIMPORT __declspec(dllimport)
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Hi,
What is the reason your software is built using "wrong" calling convention?
Do you use some 3rd party closed source DLL that link this way? Or you just like it?
Or maybe you can build a DLL yourself and just load it dynamically and then call a function in that DLL?
Please explain the reasoning.
Thank you.
What is the reason your software is built using "wrong" calling convention?
Do you use some 3rd party closed source DLL that link this way? Or you just like it?
Or maybe you can build a DLL yourself and just load it dynamically and then call a function in that DLL?
Please explain the reasoning.
Thank you.
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Please post the wxWidgets version?Sridhar@Work wrote: ↑Mon Jan 18, 2021 2:28 pm I tried compiling the source using "nmake /f makefile.vc BUILD=release SHARED=1 TARGET_CPU=X86 CPPFLAGS="/Gz"" but it is givining linker error whilst compiling the code.
Please post the error message you got when you compile wxWidgets?
Edit: Your code that uses wxWidgets need to be compatible with the wxWidgets libraries you use!
In other words, you can not do some build related changes in only your code without doing compatible changes to wxWidgets!
Tim S.
-
- Filthy Rich wx Solver
- Posts: 221
- Joined: Fri Jan 08, 2021 8:19 am
Re: Compile wxWidgets source using __stdcall instead of __cdecl on Windows
Hi
We are using wxWidgets-3.1.4 verison.
We changed our wxWidgets dll to build using cdecl and exported our internal library code functions to use stdcall using extern "c". It fixed the issue for us.
Resolution:
1. wxWidgets source can be built using cdecl calling convention as done.
2. Our wxWidgets dll is built using cdecl calling convention.
3. Our internal libraries are built using stdcall calling convention.
4. Our internal libraries are linked with our wxWidgets dll as cdecl calling convention. Any references to our exported functions are referred using stdcall and any references from our code to wxWidget dll are referred using cdecl explictly to fix the issue.
Thank you for the support.
Regards
Sree
We are using wxWidgets-3.1.4 verison.
We changed our wxWidgets dll to build using cdecl and exported our internal library code functions to use stdcall using extern "c". It fixed the issue for us.
Resolution:
1. wxWidgets source can be built using cdecl calling convention as done.
2. Our wxWidgets dll is built using cdecl calling convention.
3. Our internal libraries are built using stdcall calling convention.
4. Our internal libraries are linked with our wxWidgets dll as cdecl calling convention. Any references to our exported functions are referred using stdcall and any references from our code to wxWidget dll are referred using cdecl explictly to fix the issue.
Thank you for the support.
Regards
Sree