Re: [Dev-C++] =?gb2312?B?tPC4tDogSG93IHRvIGJ1aWxkIGEgRExMIHdpdGggZGVmIGZpbGWjvw==?=
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2006-08-09 09:48:16
|
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); }
=2E..
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; }
=2E..
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 wi=
th
> specify export function name!
> Thanks a lot!
>
> Hongquan
>
> -----=D3=CA=BC=FE=D4=AD=BC=FE-----
> =B7=A2=BC=FE=C8=CB: HongQuan.Zhang [mailto:hon...@i-...]
> =B7=A2=CB=CD=CA=B1=BC=E4: 2006=C4=EA8=D4=C29=C8=D5 17:16
> =CA=D5=BC=FE=C8=CB: 'Dev...@li...'
> =D6=F7=CC=E2: How to build a DLL with def file=A3=BF
>
> Hi=A3=ACAll:
> =09I create a dll project and I want to export some function such as
> =09void Test();
> =09I add a def file like def file in MSVC,and of course I add a linker
> opiton "-def test.def"
> =09 in project options->parameter->linker
> =09In 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'
>
>
>
>
|