alank2 5 Posted November 18, 2021 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 Share this post Link to post
Remy Lebeau 1398 Posted November 18, 2021 (edited) 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 November 18, 2021 by Remy Lebeau Share this post Link to post
alank2 5 Posted November 18, 2021 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
Remy Lebeau 1398 Posted November 19, 2021 (edited) 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 November 19, 2021 by Remy Lebeau Share this post Link to post
Fraser 2 Posted November 20, 2021 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
alank2 5 Posted November 20, 2021 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
alank2 5 Posted November 22, 2021 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
alank2 5 Posted November 30, 2021 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