Thread: [Dev-C++] =?gb2312?B?tPC4tDogSG93IHRvIGJ1aWxkIGEgRExMIHdpdGggZGVmIGZpbGWjvw==?=
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: HongQuan.Zhang <hon...@i-...> - 2006-08-09 09:26:38
|
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=20
-----=D3=CA=BC=FE=D4=AD=BC=FE-----
=B7=A2=BC=FE=C8=CB: HongQuan.Zhang [mailto:hon...@i-...]=20
=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:
I create a dll project and I want to export some function such as=20
void Test();
I add a def file like def file in MSVC,and of course I add a linker
opiton "-def test.def"
in project options->parameter->linker=20
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'=20
|
|
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'
>
>
>
>
|
|
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'
>
>
>
>
|
|
From: Per W. <pw...@ia...> - 2006-08-09 11:41:13
|
I do dynamic loading of libraries in my applications too using something
like the following for Win32 applications. Normally I hide a bit more of
the code in macros, to make it work with Linux too.
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
extern "C" {
DLLIMPORT DWORD __cdecl GetObjectFactoryCount();
DLLIMPORT bool __cdecl GetObjectFactory(DWORD n,ObjectFactoryInfo& info);
}
hLib =3D LoadLibrary(pszName);
GetObjectFactoryCount =3D
(suitable cast)GetProcAddress(hLib,"GetObjectFactoryCount");
GetObjectFactory =3D
(suitable cast)GetProcAddress(hLib,"GetObjectFactory");
/Per W
On Wed, 9 Aug 2006, HongQuan.Zhang wrote:
> Per Westermark=EF=BC=9A
> =09Thank you for answer my question.
> =09I don't want to use __declspec(dllexport),because this director will =
output a function name with additional characters which are added by compil=
er.
> =09Example:
> =09void=09Test(int a);
> =09maybe output like this "_test@4"
> =09I just want to output with name "Test" , So I can use LoadLibrary and =
GetProcAddress to get the function address easily!
> =09That is,I need to load the dll and invoke the function dynamicly!
>
> =09In MSVC ,I can only need to do is provide a def file and write the fun=
ction name down and compile!
>
> =09Anyway,thanks again!
>
>
>
> Hongquan
>
>
>
>
> -----=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...]
> =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2006=E5=B9=B48=E6=9C=889=E6=97=A5 1=
7: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 digit=
s and characters are added to the name to distinguish type information. Thi=
s 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 fu=
lly mangled name.
>
> Or, you have to declare the function as type "C", to avoid the name mangi=
ng. 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 exporte=
d 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 com=
patible 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:hongquan.z=
ha...@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....=
net'
> > =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:
> > =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'
> >
> >
> >
> >
>
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job ea=
sier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim=
o
> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=
=3D121642
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|