[SOLVED] Windows DLL _stdcall without name mangeling

  • Hello !
    Sorry for my simple newbie in Qt question but I found no easy solution in the net.
    I want create simple windows-dll and I must use _stdcall. How can I give the exported functions a custom (simple "extern C") name.
    Has Qt (gmake) a mechanism to obtain and forward it to gcc resp. the linker.

  • Moderators

    Hi, welcome to devnet.

    This question is not really related to Qt (which is just another c++ library). The way you do this is specific to your compiler.
    If you want unmangled names then are you sure you want __stdcall and not __cdecl?

    If you want to undecorate the __stdcall functions created with MSVC you can either create a .def file for your library or use the /export linker switch.

    The way to pass custom params to linker when you're using qmake is by adding it to the .pro file with the QMAKE_LFLAGS i.e.
    QMAKE_LFLAGS += your_params_here.

  • Yes it has indeed nothing to do with Qt and its a compiler specific.
    Because both Qt and GCC is very new for me I asked the question.

    I found a simple solution for MinGW
    QMAKE_LFLAGS += -Wl,--add-stdcall-alias
    which integrated the simple names additional.

  • What is wrong in using extern C in declaration?
    Then you can check for specific compiler.
    Something like below:

    #ifdef __cplusplus
    extern "C" {

    #ifndef __STDCALL
    #if defined(_WIN32) && defined(_MSC_VER)
    #define __STDCALL __stdcall
    #define __STDCALL

    int __STDCALL myFunction1();
    void __STDCALL myFunction2();

    #ifdef __cplusplus
    } // end of extern "C"

  • Moderators

    Cool. Thanks for sharing.

  • Moderators

    @alex_malyu __stdcall, as opposed to __cdecl decorates even functions marked as extern "C". You need additional linker support to undecorate them or a .def file.

  • Above posted code works for on WIndows up to VS2013 with Microsoft and Intel compilers + on Linux with Intel compiler and GCC.
    I am pretty sure about naming, cause our code involves Fortran which would not be able to call any C routine otherwise.

  • Moderators

    Yes, but notice that above code uses __cdecl for anything but MSVC.

  • You are right, I forgot we never used GCC on Windows and always __cdecl f on other platforms.

Log in to reply