Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Windows DLL _stdcall without name mangeling
QtWS25 Last Chance

[SOLVED] Windows DLL _stdcall without name mangeling

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    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.
    Thanks

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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.

      1 Reply Last reply
      0
      • Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        1
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by alex_malyu
          #4

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

          #ifdef __cplusplus
          extern "C" {
          #endif

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

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

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

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Cool. Thanks for sharing.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alex_malyu
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alex_malyu
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved