Still porting my dll. I've finally made it compile, but ... the mangled names are missing a leading underscore (I'm looking at the dll with a hex editor).
prototypes for exports look like this:
extern "C" { //doesn't matter much if I leave this out
__declspec (dllexport) void __stdcall some_function(int blah);
//more declarations of this type here
}
Which results in the following mangled name:
some_function@4
This is almost it, with the exception of the leading underscore. Ie
_some_function@4
I've honestly tried, I've used -fleading-underscore as compiler option, but that didn't change a thing (?). Is renaming all functions the only way to get the desired export names?
I hate to say it, but that would break portability with MSVC *eg*
Possibly unrelated, but I've also kind of lost my DllMain export ... it's not in the generated DLL, though the function is properly defined.
Current command line stuff in project options:
Compiler: -shared -DBUILD_DLL -fleading_underscore
Linker: --no-export-all-symbols -lopengl32 -lgdi32 "assembly.obj" -s
As said, compiles without warning, links without warning, generates a proper DLL. It's all about the name mangling and DllMain.
Sorry if I'm just being dumb, but it's been a busy night and I'm tired, hope you can help me out.
Puzzled,
-zeckensack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ugh, just forget about DllMain ... I've just noticed that it's also not in the MSVC generated DLL. That has been working fine all the time, and that can only mean one thing:
I need to learn more about DLLs.
Sorry
Grabbing more coffee
-zeckensack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay, I thing I've found a solution to my underscore problem. It's somewhat messy but here goes, in case anyone's interested:
//in header
//check for MSVC
#ifdef _MSC_VER
#define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall name parms
#define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall name parms
#endif
//check for GCC/MingW
#ifdef __GNUC__
#define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall _##name parms
#define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall _##name parms
#endif
Re: RTFM. I would have liked to. Honestly. I've tried the dll_wrap_ docs, which obiously wasn't the right place to look. Binutils still confuse me a bit. Thanks to your intervention I've finally found what I need.
Grateful anyway,
-zeckensack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Still porting my dll. I've finally made it compile, but ... the mangled names are missing a leading underscore (I'm looking at the dll with a hex editor).
prototypes for exports look like this:
extern "C" { //doesn't matter much if I leave this out
__declspec (dllexport) void __stdcall some_function(int blah);
//more declarations of this type here
}
Sample definition:
__declspec (dllexport) void __stdcall some_function(int blah)
{
//yadda yadda
}
Which results in the following mangled name:
some_function@4
This is almost it, with the exception of the leading underscore. Ie
_some_function@4
I've honestly tried, I've used -fleading-underscore as compiler option, but that didn't change a thing (?). Is renaming all functions the only way to get the desired export names?
I hate to say it, but that would break portability with MSVC *eg*
Possibly unrelated, but I've also kind of lost my DllMain export ... it's not in the generated DLL, though the function is properly defined.
Current command line stuff in project options:
Compiler: -shared -DBUILD_DLL -fleading_underscore
Linker: --no-export-all-symbols -lopengl32 -lgdi32 "assembly.obj" -s
As said, compiles without warning, links without warning, generates a proper DLL. It's all about the name mangling and DllMain.
Sorry if I'm just being dumb, but it's been a busy night and I'm tired, hope you can help me out.
Puzzled,
-zeckensack
Ugh, just forget about DllMain ... I've just noticed that it's also not in the MSVC generated DLL. That has been working fine all the time, and that can only mean one thing:
I need to learn more about DLLs.
Sorry
Grabbing more coffee
-zeckensack
Okay, I thing I've found a solution to my underscore problem. It's somewhat messy but here goes, in case anyone's interested:
//in header
//check for MSVC
#ifdef _MSC_VER
#define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall name parms
#define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall name parms
#endif
//check for GCC/MingW
#ifdef __GNUC__
#define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall _##name parms
#define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall _##name parms
#endif
DECLARE_EXPORT(grDrawPoint,void,(const Vertex* point));
__________________
//in cpp
IMPLEMENT_EXPORT(grDrawPoint,void,(const Vertex* point))
{
//yadda yadda
}
___________________
Actually quite simple :-)
-zeckensack
From Dlltool documentation...
-U
--add-underscore
Specifies that when dlltool is creating the exports file it should prepend an underscore to the names of the exported functions.
RTFM
Toni
Huge thanks for the switch! :-)
Re: RTFM. I would have liked to. Honestly. I've tried the dll_wrap_ docs, which obiously wasn't the right place to look. Binutils still confuse me a bit. Thanks to your intervention I've finally found what I need.
Grateful anyway,
-zeckensack