Board index » cppbuilder » Linker Error with importet DLL

Linker Error with importet DLL


2006-03-20 12:07:09 AM
cppbuilder112
I've used a xyz.dll in some of my BCB6 projects. To use this dll, the
entries are defined in a header file with WINAPI and for the dll, i've
created a import lib with IMPLIB.EXE. Than i include this xyz.lib in my
project.
After moving to BDS2006, i always get a message:
[Linker Fehler] Error: Ungelöste externe '_ReginaVersion' referenziert
von T:\TEMP\CPPB\HOST\TSOREXX.OBJ
Ok, its german, but it means unresolved external referenz.
The function is defined in the header file as:
APIRET APIENTRY ReginaVersion(
PRXSTRING VersionString )
EXTNAME("ReginaVersion");
#define REGINAVERSION ReginaVersion
Thanks in advance
Erwin
 
 

Re:Linker Error with importet DLL

It sounds as if the macro APIENTRY is not correctly defined or that the
function is not marked as extern "C". It should eventually map to __stdcall
just as the macro WINAPI does.
Try this:
tdump filename.OBJ | grep "ReginaVersion"
tdump xyz.DLL | grep "ReginaVersion"
That will list the text of the function's public name in the object file and
in the DLL. The public names should match.
If a function is extern "C" and __stdcall then it will be the same as in the
source code (here "ReginaVersion"). If extern "C" but not __stdcall then
"_ReginaVersion" and if neither then it will be something odd like
"@ReginaVersion$qv".
You can see the name as used in your program by looking at the object file
with a command such as this:
As for:
Quote
EXTNAME("ReginaVersion");
I do not know of the EXTNAME macro and can think of no reason for it to be
needed.
. Ed
Quote
Erwin Marschalk wrote in message
news:441d81b1$ XXXX@XXXXX.COM ...

I've used a xyz.dll in some of my BCB6 projects. To use this dll, the
entries are defined in a header file with WINAPI and for the dll, i've
created a import lib with IMPLIB.EXE. Than i include this xyz.lib in my
project.

After moving to BDS2006, i always get a message:

[Linker Fehler] Error: Ungelöste externe '_ReginaVersion' referenziert von
T:\TEMP\CPPB\HOST\TSOREXX.OBJ

Ok, its german, but it means unresolved external referenz.

The function is defined in the header file as:

APIRET APIENTRY ReginaVersion(
PRXSTRING VersionString )
EXTNAME("ReginaVersion");
#define REGINAVERSION ReginaVersion
 

Re:Linker Error with importet DLL

Hi Ed,
the TDUMP shows, what is expected. In the obj file, the name is
_ReginaVersion, in the dll, its ReginaVersion. So the error of the
linker is correct. I can solve this problem, if i tell the compiler to
not create underscores. But if i do that, i get link problems with the
_main entry point. Also with BCB6 i have set the -u option and anything
works.
The macro EXTNAME is empty in my case. Its only in the headerfile if the
REGINA.DLL needs to be compiles with the ming compiler. WINAPI is, i
think, coming from the windows.h files.
Btw. how can i check the contents of the WINAPI macro. I tried
#pragma message M_APIENTRY = ' APIENTRY '
but this returns the message as is, although the help says, in this
case, the macros should be expanded.
Erwin
Ed Mulroy schrieb:
Quote
It sounds as if the macro APIENTRY is not correctly defined or that the
function is not marked as extern "C". It should eventually map to __stdcall
just as the macro WINAPI does.

Try this:

tdump filename.OBJ | grep "ReginaVersion"
tdump xyz.DLL | grep "ReginaVersion"

That will list the text of the function's public name in the object file and
in the DLL. The public names should match.

If a function is extern "C" and __stdcall then it will be the same as in the
source code (here "ReginaVersion"). If extern "C" but not __stdcall then
"_ReginaVersion" and if neither then it will be something odd like
"@ReginaVersion$qv".

You can see the name as used in your program by looking at the object file
with a command such as this:

As for:
>EXTNAME("ReginaVersion");

I do not know of the EXTNAME macro and can think of no reason for it to be
needed.

. Ed

>Erwin Marschalk wrote in message
>news:441d81b1$ XXXX@XXXXX.COM ...
>
>I've used a xyz.dll in some of my BCB6 projects. To use this dll, the
>entries are defined in a header file with WINAPI and for the dll, i've
>created a import lib with IMPLIB.EXE. Than i include this xyz.lib in my
>project.
>
>After moving to BDS2006, i always get a message:
>
>[Linker Fehler] Error: Ungelöste externe '_ReginaVersion' referenziert von
>T:\TEMP\CPPB\HOST\TSOREXX.OBJ
>
>Ok, its german, but it means unresolved external referenz.
>
>The function is defined in the header file as:
>
>APIRET APIENTRY ReginaVersion(
>PRXSTRING VersionString )
>EXTNAME("ReginaVersion");
>#define REGINAVERSION ReginaVersion


 

{smallsort}

Re:Linker Error with importet DLL

I assume that this program uses the VCL. If that is correct then vcl.h
should be the first header file included. I do not think the VCL set of
header files defines the macro APIENTRY.
You can try adding something like this after the system headers:
----------------
#ifdef APIENTRY
#undef APIENTRY
#endif
#define APIENTRY WINAPI
----------------
If the program does not use the VCL then add an include of windows.h as the
first header file included.
. Ed
Quote
Erwin Marschalk wrote in message
news:441e661e$ XXXX@XXXXX.COM ...

the TDUMP shows, what is expected. In the obj file, the name is
_ReginaVersion, in the dll, its ReginaVersion. So the error of the linker
is correct. I can solve this problem, if i tell the compiler to not create
underscores. But if i do that, i get link problems with the _main entry
point. Also with BCB6 i have set the -u option and anything works.

The macro EXTNAME is empty in my case. Its only in the headerfile if the
REGINA.DLL needs to be compiles with the ming compiler. WINAPI is, i
think, coming from the windows.h files.

Btw. how can i check the contents of the WINAPI macro. I tried

#pragma message M_APIENTRY = ' APIENTRY '

but this returns the message as is, although the help says, in this case,
the macros should be expanded.
 

Re:Linker Error with importet DLL

Hi ED,
your tip was good. The program doesn't use the VCL. At the beginning,
there where some std..h files and in the first user header file, there
was a conditionally include of the windows.h.
#if defined(WIN32) && (defined(__WATCOMC__) || defined(__BORLANDC__))
# include <windows.h>
#endif
It looks like, that in BCB6 the condition was true and the windows.h was
included. In BDS2006, the condition was not true and the windows.h was
not included.
After i included the windows.h in the main program file, everything
works fine.
Thanks
Erwin
Ed Mulroy schrieb:
Quote
I assume that this program uses the VCL. If that is correct then vcl.h
should be the first header file included. I do not think the VCL set of
header files defines the macro APIENTRY.

You can try adding something like this after the system headers:

----------------
#ifdef APIENTRY
#undef APIENTRY
#endif

#define APIENTRY WINAPI
----------------

If the program does not use the VCL then add an include of windows.h as the
first header file included.

. Ed

>Erwin Marschalk wrote in message
>news:441e661e$ XXXX@XXXXX.COM ...
>
>the TDUMP shows, what is expected. In the obj file, the name is
>_ReginaVersion, in the dll, its ReginaVersion. So the error of the linker
>is correct. I can solve this problem, if i tell the compiler to not create
>underscores. But if i do that, i get link problems with the _main entry
>point. Also with BCB6 i have set the -u option and anything works.
>
>The macro EXTNAME is empty in my case. Its only in the headerfile if the
>REGINA.DLL needs to be compiles with the ming compiler. WINAPI is, i
>think, coming from the windows.h files.
>
>Btw. how can i check the contents of the WINAPI macro. I tried
>
>#pragma message M_APIENTRY = ' APIENTRY '
>
>but this returns the message as is, although the help says, in this case,
>the macros should be expanded.