August 2, 2011

Adi Adi
Lab Rat
206 posts

Avoiding name mangling in Qt dll

 

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?

7 replies

August 2, 2011

Gerolf Gerolf
Area 51 Engineer
3213 posts

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

  1. extern "C"
  2. {
  3.     // my C-functions to export
  4. }

 Signature 

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

August 2, 2011

Adi Adi
Lab Rat
206 posts

Hi

below is my example code

  1. class Temp
  2. {
  3.     void fun1();
  4.     void fun2();
  5. };

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

August 2, 2011

Gerolf Gerolf
Area 51 Engineer
3213 posts

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:

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

 Signature 

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

August 2, 2011

Adi Adi
Lab Rat
206 posts

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.

August 2, 2011

Gerolf Gerolf
Area 51 Engineer
3213 posts

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.

 Signature 

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

August 2, 2011

ZapB ZapB
Robot Herder
1359 posts

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.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

August 6, 2011

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

… and you cannot use simple functions pointers to call methods on objects [parashift.com].

 
  ‹‹ [SOLVED] New to programming, some questions about Qt      getting locale information from string ››

You must log in to post a reply. Not a member yet? Register here!