954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Name mangling: C++ static library

I have a name mangling issue with a C++ static library that was created using VS 6.0. I'm trying to write a wrapper DLL using this static library, but i'm having trouble accessing the functions of this library due to name mangling. My compiler (VS 2005) shows this for a function i'm trying to use:

"?start_api@@YACH@Z",

and dumbin shows this for the reference to the function:

"?start_api@@YA_DH@Z"


As you can see my compiler says its returning signed char and looking for an int (CH). Where in dumpbin it says its returning a __int8 and looking for an int (_DH).

The static library is a 3rd party library that i don't have the source for and can't rewrite, so how do I get it working in my compiler?

wrxhokie
Newbie Poster
10 posts since Mar 2009
Reputation Points: 9
Solved Threads: 0
 

Looks like the function is prototyped incorrectly. Change the prototype in the header file to match the library.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

When importing a static library in visual studio, you don't have to declare it in your source. You just have the reference the library, include the header files (which i can't modify), and call the function.

Its prototyped correctly in the header, as returning a __int8 and returning and int. But my compiler refuses to see it that way. It sees it as a signed char even though dumpbin says its a __int8 like the header shows.

wrxhokie
Newbie Poster
10 posts since Mar 2009
Reputation Points: 9
Solved Threads: 0
 

why can't you change the header file? If its on your computer than you can change it. Save a copy somewhere else and if changing the header file doesn't work then change it back.

Of course you can always just call the people who wrote the library and ask them.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I changed the header file and it gave me the same unresolved external error. I changed the prototype to be a signed char like my compiler is seeing, and it still didn't like it. Here's the error:

Error 3 error LNK2019: unresolved external symbol "signed char __cdecl start_api(int)" (?start_api@@YACH@Z) referenced in function "bool __cdecl start_core(int)" (?start_core@@YA_NH@Z) CoreWrapper.obj

wrxhokie
Newbie Poster
10 posts since Mar 2009
Reputation Points: 9
Solved Threads: 0
 

The error message has not changed. It appears you did not change it correctly, there may be more than one occurrence of the prototype, or there may be multiple copies of the header file.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Unfortunately, there is only one occurrence of the prototype, and thats in the header of the static library.

I'm really at a loss at this point...

wrxhokie
Newbie Poster
10 posts since Mar 2009
Reputation Points: 9
Solved Threads: 0
 

Unfortunately, there is only one occurrence of the prototype, and thats in the header of the static library.

I'm really at a loss at this point...

You might try posting on the MSDN's Visual C++ General forum.

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

Thanks, i'll try there.

wrxhokie
Newbie Poster
10 posts since Mar 2009
Reputation Points: 9
Solved Threads: 0
 

after changing the header file did you re-compile everything?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You