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. Avoiding name mangling in Qt dll
QtWS25 Last Chance

Avoiding name mangling in Qt dll

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 6.1k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

    I have created a -QT- Qt Library.
    But when i try to use that dll I see the names of all the functions in dll are name mangled.

    How to avoid this?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      first of all, which platform and which compiler tool chain do you use?

      C++ has no definitions, how names are exported. If you want to export C style functions, you have to mark this section as C

      @
      extern "C"
      {
      // my C-functions to export
      }
      @

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Indrajeet
        wrote on last edited by
        #3

        Hi

        below is my example code
        @class Temp
        {
        void fun1();
        void fun2();
        };@

        My above code is developed as -QT- Qt Library.
        but when I try to use extern "C" for each function it gives me error.
        Is there any keyword in QT which is equivalent to extern "C".

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          extern "C" only works for functions, not for class members. Class members will always be mangled names.

          Why do you need that?

          and you did not answer my first question:

          bq. first of all, which platform and which compiler tool chain do you use?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Indrajeet
            wrote on last edited by
            #5

            Hi

            I am using Visual studio 2010.
            I want to load my dll dynamically in client application.
            And use function pointers to call functions from the class.

            So wat is the solution for class members to avoid name mangling.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              There is no. You can't load a dll dynamically and call class members idrectly, this is not possible. If you want to use classes, use a creator design pattern with interfaces or use early binding.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #7

                Name mangling is part of the C++ ABI you cannot disable it. You'll need to wrap the management of your C++ objects in plain C functions and be sure to mark those functions as extern "C" as Gerolf said.

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  ... and you cannot use simple functions pointers to "call methods on objects":http://www.parashift.com/c++-faq-lite/pointers-to-members.html.

                  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