OS/2, eCS & ArcaOS - Technical > Programming
GCC/G++ - how to export global variable without underscore?
Andi B.:
I'm trying to build a dll which should export some functions and global variables. I made this long time ago I think with our gcc3.xx but now want to do the same with our g++.exe (GCC) 9.2.0.
I think exporting symbols is disabled now by default so I added to the functions I want to export
--- Code: ---__attribute__ ((dllexport))
--- End code ---
which works fine. Now when I look at my dll with
--- Code: ---lxlite /C:exp myown.dll
--- End code ---
I see the exported functions as I expected.
But my global variables still have the C naming convention leading _ which I don't like. F.i. I have -
--- Code: ---00048 │ _NdpAttribute
00049 │ _NdpPropertiesInfo
00050 ┴ _NdpTypes
--- End code ---
but I wanna have them without the _
The variables are defined that way -
--- Code: ---__attribute__ ((dllexport)) extern const char *NdpTypes[];
--- End code ---
and I use g++ instead gcc. So I thought it should work the same as with the functions (they don't have the _).
Any thoughts?
Dave Yeo:
It's the calling convention, cdecl vs stdcall. I think you need __attribute__ ((__cdecl)), might be ((__stdlib)) and __declspec instead of __attribute__
--- Code: ---__attribute__ ((dllexport)) __attribute__((__stdcall)) extern const char *NdpTypes[];
--- End code ---
or __cdecl
Been a while since I thought about this so sorry for being unclear, needed it in the past for linking OW and GCC.
gcc vs g++ shouldn't matter
Andi B.:
I tried various combinations of dllexport (which seems to be mandatory to export the symbol) and stdcall cdecl... But I ever end up with exporting _NdpTypes instead NdpTypes. I was under the impression that c++ don't add the _ but obviously I misinterpreted some stuff.
Another idea, is there any emx tool which can modify the exported symbols? Or add a new symbol to a dll which references to the orignal?
Btw. this all started cause I didn't manage to convince c++/linker to work with a .def file as it was used with icc or watcom. You know I'm not experienced with all this stuff so there is much guessing on my side.
Paul Smedley:
Isn't it _System to use non-underscored variable names?
Dave Yeo:
--- Quote from: Paul Smedley on July 15, 2024, 10:16:44 am ---Isn't it _System to use non-underscored variable names?
--- End quote ---
Might be.
Navigation
[0] Message Index
[#] Next page
Go to full version