Jump to content
alank2

DLL without underscore mangled functions

Recommended Posts

When I turn off the option "Generate underscores on symbol names" to eliminate them, then I get linker errors for some built in library functions:

 

wcslen/wcscpy/wcscmp/qsort_s

 

Any ideas why?  I am running 10.3.3

image.png

Share this post


Link to post
4 hours ago, alank2 said:

When I turn off the option "Generate underscores on symbol names" to eliminate them, then I get linker errors for some built in library functions

You really should not mess with the compiler's mangling settings.  If you want to export your own functions without underscores, use a DEF file to handle that:

 

https://docs.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files

https://docs.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-def-files

https://docwiki.embarcadero.com/RADStudio/en/Module_Definition_Files

https://docwiki.embarcadero.com/RADStudio/en/IMPDEF.EXE,_the_Module_Definition_Manager

https://docwiki.embarcadero.com/RADStudio/en/MKEXP.EXE,_the_64-bit_Windows_Import_Library_Tool_for_C%2B%2B

Edited by Remy Lebeau

Share this post


Link to post

I made a DEF file and put an EXPORTS section into it and added it to the project.  I also added lines for each function like this:

 

function=_function

 

This does produce a DLL, but it has both function names in it now.  function and _function.  Is there a way to remove _function so that only function is present?

Share this post


Link to post
On 11/18/2021 at 1:48 PM, alank2 said:

Is there a way to remove _function so that only function is present?

When exporting your own functions, simply don't mark your original function as being exported from code (via either __declspec(dllexport) or __export), let the DEF file handle the exporting, so you control the format of the mangling.  But, for library functions, I don't think you can do this.

Edited by Remy Lebeau

Share this post


Link to post

I use extern "C" to prevent name mangling like this;

 

extern "C" {

__declspec(dllexport) signed char __stdcall MajorVersion() {
    return 1;
    };
}

 

Share this post


Link to post

I keep reading this, but I am already have the function wrapped in extern "C" and it still has the underscore.  DId some C compilers use an underscore and others not?

 

Trying to make sense of this - do I have these right?

 

Without extern "C", will it be the mangled C++ name with parameter suffix?

 

With extern "C", will it simply be mangled to have a simple underscore before it.

 

With extern "C" _and_ generate underscores option off, then it will drop the underscore, but then be incompatible with standard libraries.

 

Share this post


Link to post

ALSO, is there a way to make a DEF file apply to only the 32-bit target platform in cppbuilder?

Share this post


Link to post

Thanks Remy; pulling the __declspec(dllexport) allowed me to just export them in the DEF file.  I didn't find a way to use a single project for both win32 and win64 so I put them in different projects with different DEF files and used a projectgroup to contain them both.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×