Generate a DLL with __stdcall calling convention
-
wrote on 30 Mar 2012, 15:12 last edited by
Hi,
I am generating a shared library(DLL) in Windows using QT Creator. I am facing a problem with this shared library (DLL).
I have to generate a Library with __stdcall calling convention. By default it is created with __cdecl calling convention.
I want to override this calling convention.
Could you please help me to achieve this.
Thanks & Regards,
Ramanujam -
wrote on 30 Mar 2012, 17:40 last edited by
Hi Ramanujam,
Qt does not do anything magic for this. If you want to export the funcation with __stdcall, you should add "__stdcall" to the function, which is exactly the same as you do when you using pure C/C++.
Regards,
Debao
-
wrote on 31 Mar 2012, 06:13 last edited by
Hi Debao,
Thanks for your answer. Actually I am aware of __stdcall.
I will explain you the problem what I am facing.I am using third party library where all functions are in __stdcall calling convention. Third party library is a static library and it has a header file.
Static library has a function
void __stdcall SomeFunction()
{
}but in header file its prototype is
void SomeFunction();What is happening is when I include header file in my Shared library(DLL) is
SomeFunction() is considered as __cdecl because __stdcall is missing from prototype declaration in header file and Shared library by default was compiled in __stdcall calling convention.When I call SomeFunction() from my DLL it is giving a linker error because calling convention is mismatching with the function definition.
I contacted the third party vendor and they said I have to change the project settings to __stdcall (/Gz) compiler option. It will solve the problem. For testing purpose I changed the prototype declaration to
void __stdcall SomeFunction(); then Shared library is linking fine. But this is not the correct solution because third party library is licensed and I can't change the header file of a third party library.I hope you understood the problem. What I want is how can I change the QT project settings to include __stdcall convention similar to Visual studio where you change the calling convention from Project-->Properties-->C/C++-->Advanced-->Calling Convention.
Basically what I need is How to include the library which uses __stdcall convention for all the functions with the DLL which uses __cdecl convention...............
Please help me.....
Thanks & Regards,
Ramanujam -
wrote on 31 Mar 2012, 22:51 last edited by
You can add following line to your .pro file.
@
QMAKE_CFLAGS += /Gz
QMAKE_CXXFLAGS += /Gz
@Regards,
Debao
-
wrote on 1 Apr 2012, 02:54 last edited by
Thanks a lot....
Linking with third party library is fine now. But due this compiler option there is one more linker error in QString.
I have done one sample and below are the steps
- Created a shared library to include QtCore modules
- included QtCore in my cpp file and added
QString test = QString::number(5000); to convert number into a QString. - Then added the
QMAKE_CFLAGS += /Gz
QMAKE_CXXFLAGS += /Gz
int the .pro file - Rebuild entire project
There are linker errors for these QString. If I remove above options from a .pro file it links successfully.
My observation is accessing all static member functions of a class are giving linker error with this compiler option.
For Example:
quint64 g_ulCurrentPID = QCoreApplication::applicationPid();
Also my project settings include "UNICODE" and "No (/Zc:wchar_t-)". I tried with "treat _wchar_t as default Built-in Type" as Yes. Still I am facing the same problem.Could you please help to solve this linker error
Thanks & Regards,
Ramanujam -
wrote on 22 Oct 2012, 12:55 last edited by
I'm facing a similar problem changing calling convention to cdecl gives "Interlocked" errors in files qatomic_windows.h and intrin.h. I'm tried on Visual Studio using QT VS Plugin and QT Creator.
Steps to recreate:
Visual StudioCreate a QT console application.
VS properties -> Configuration Properties -> C/C++ -> Advanced -> Calling Convention.
Change to __stdcall (/Gz)
Qt Creator
Create a console or any other application
In the .pro file add the following lines
QMAKE_CFLAGS += /Gz
QMAKE_CXXFLAGS += /GzBuild the project
Platform Details:
Windows 7 64 bit
Visual Studio 2010
QT Version 4.8.2