[Dev-C++] =?utf-8?b?562U5aSNOiAg562U5aSNOiBIb3cgdG8gYnVpbGQgYSBE?= =?utf-8?q?LL_with_def_file=EF=BC
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: HongQuan.Zhang <hon...@i-...> - 2006-08-09 10:16:00
|
Per Westermark=EF=BC=9A
Thank you for answer my question.
I don't want to use __declspec(dllexport),because this director will =
output a function name with additional characters which are added by =
compiler.
Example:
void Test(int a);
maybe output like this "_test@4"
I just want to output with name "Test" , So I can use LoadLibrary and =
GetProcAddress to get the function address easily!
That is,I need to load the dll and invoke the function dynamicly!
=09
In MSVC ,I can only need to do is provide a def file and write the =
function name down and compile!
=09
Anyway,thanks again!
Hongquan
=09
-----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6-----
=E5=8F=91=E4=BB=B6=E4=BA=BA: Per Westermark =
[mailto:pw...@ia...]=20
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2006=E5=B9=B48=E6=9C=889=E6=97=A5 =
17:48
=E6=94=B6=E4=BB=B6=E4=BA=BA: HongQuan.Zhang
=E6=8A=84=E9=80=81: Dev...@li...
=E4=B8=BB=E9=A2=98: Re: [Dev-C++] =E7=AD=94=E5=A4=8D: How to build a DLL =
with def file=EF=BC=9F
Note that in C++, the external name of functions are mangled. Extra =
digits and characters are added to the name to distinguish type =
information. This is needed since C++ allows multiple functions with the =
same name but with different signatures. For example:
int Test() { return 0}
int Test(int a) { return a; }
int Test(int a,int b) { return a+b; }
int Test(const char* s) { return strlen(s); } ...
If you use a file to specify exported symbols, you have to specify the =
fully mangled name.
Or, you have to declare the function as type "C", to avoid the name =
manging. The function will then just get an initial underscore in it's =
external name - _Test.
When developing on Windows systems, it is quite common to use the M$
extension:
__declspec(dllexport)
before name of exported symbols directly in the source code.
The linker will then be able to extract the information about all =
exported symbols automatically, without the need of the def file.
You might have code:
__declspec(dllexport) int my_variable;
__declspec(dllexport) int Test() { return 0; } ...
Normally the dll declaration is hidden in a #define, to make the code =
compatible with compilers/environments that doesn't support DLL files.
#define __declspec(dllexport) EXPORT
EXPORT int my_variable;
EXPORT int Test() { return 0; }
In the same way, code that needs to access a function or variable =
defined in a DLL may use __declspec(dllimport) instead.
/Per W
On Wed, 9 Aug 2006, HongQuan.Zhang wrote:
> I am sorry that I haven't finish the post before I send it!
> the original message is at below.
> And I just want to know how to code the def file,or how to build a dll =
> with specify export function name!
> Thanks a lot!
>
> Hongquan
>
> -----=C3=93=C3=8A=C2=BC=C3=BE=C3=94=C2=AD=C2=BC=C3=BE-----
> =C2=B7=C2=A2=C2=BC=C3=BE=C3=88=C3=8B: HongQuan.Zhang =
[mailto:hon...@i-...]
> =C2=B7=C2=A2=C3=8B=C3=8D=C3=8A=C2=B1=C2=BC=C3=A4: =
2006=C3=84=C3=AA8=C3=94=C3=829=C3=88=C3=95 17:16
> =C3=8A=C3=95=C2=BC=C3=BE=C3=88=C3=8B: =
'Dev...@li...'
> =C3=96=C3=B7=C3=8C=C3=A2: How to build a DLL with def file=C2=A3=C2=BF
>
> Hi=C2=A3=C2=ACAll:
> I create a dll project and I want to export some function such as
> void Test();
> I add a def file like def file in MSVC,and of course I add a linker=20
> opiton "-def test.def"
> in project options->parameter->linker
> In the file Test.def,there are only several code as follow:
>
> ; test.def : Declares the module parameters for the DLL.
>
> LIBRARY "test"
> DESCRIPTION 'test Windows Dynamic Link Library'
>
> EXPORTS
> ; Explicit exports can go here
> Test
>
>
> When I compile the project and get some error:
> [Linker error] undefined reference to `Test'
>
>
>
>
|