Problem linking a VC generated static LIB into a win32 DLL project 
Author Message
 Problem linking a VC generated static LIB into a win32 DLL project

Hi all,

I'm attempting to link a static library that was generated with VC
into a win32 DLL project and cannot seem to get the DLL project to see
the lib.  There are over 100 functions in this library and I get
unresolved external errors for each one I am using.

I have the library in the project directory and have it listed under
project settings/link tab.

Within the DLL, I'm including header files for each function in the
library.

Interesting note is the link error message is:

The function name that I am trying to use within the library is
SetInitParam.

Thanks in advance,

Tim



Tue, 06 Sep 2005 00:55:14 GMT  
 Problem linking a VC generated static LIB into a win32 DLL project

Quote:

> Hi all,

> I'm attempting to link a static library that was generated with VC
> into a win32 DLL project and cannot seem to get the DLL project to see
> the lib.  There are over 100 functions in this library and I get
> unresolved external errors for each one I am using.

> I have the library in the project directory and have it listed under
> project settings/link tab.

> Within the DLL, I'm including header files for each function in the
> library.

> Interesting note is the link error message is:

> The function name that I am trying to use within the library is
> SetInitParam.

How are the functions declared in the library?

It appears that you have a calling-convention mismatch.  The caller is
expecting the functions to be '__stdcall', but I'd have to guess that the
library was compiled with a different default, or the functions were
explcitly delcared '__cdecl'.

You can use dumpbin /symbols on the library to see the names that are
exported from the library.  You can use undname.exe to "undecorate" the
exported names and the names that appear in the linker error messages to see
how the function declarations differ.

The solution will depend on exactly why the problem is occurring.

-cd



Tue, 06 Sep 2005 01:14:46 GMT  
 Problem linking a VC generated static LIB into a win32 DLL project
Thanks for your reply.

Below is the output from dumpbin on the lib.  
028 00000000 SECT6  notype ()    External     | _SetInitParam
    tag index 0000003E size 000000B0 lines 00000BD9 next function
00000049

Please note that I have the source for the library in which I am
trying to link.  You may wonder why I don't just compile that into a
DLL instead of linking it again.  The reason is the library uses yet
another library of low-level functions that were provided by a third
party, all of which are __cdecl and for the life of me I could not get
it to build as a DLL.

It isn't clear to me what the above info indicates since I can't tell
what the calling convention is, even though I compiled the library as
__cdecl.  I have tried compiling it using both __stdcall and __cdecl
with no success in linking it to the DLL project for either case.

Regards,

Tim


Quote:

> > Hi all,

> > I'm attempting to link a static library that was generated with VC
> > into a win32 DLL project and cannot seem to get the DLL project to see
> > the lib.  There are over 100 functions in this library and I get
> > unresolved external errors for each one I am using.

> > I have the library in the project directory and have it listed under
> > project settings/link tab.

> > Within the DLL, I'm including header files for each function in the
> > library.

> > Interesting note is the link error message is:

> > The function name that I am trying to use within the library is
> > SetInitParam.

> How are the functions declared in the library?

> It appears that you have a calling-convention mismatch.  The caller is
> expecting the functions to be '__stdcall', but I'd have to guess that the
> library was compiled with a different default, or the functions were
> explcitly delcared '__cdecl'.

> You can use dumpbin /symbols on the library to see the names that are
> exported from the library.  You can use undname.exe to "undecorate" the
> exported names and the names that appear in the linker error messages to see
> how the function declarations differ.

> The solution will depend on exactly why the problem is occurring.

> -cd



Tue, 06 Sep 2005 21:37:17 GMT  
 Problem linking a VC generated static LIB into a win32 DLL project

Quote:

> Thanks for your reply.

> Below is the output from dumpbin on the lib.
> 028 00000000 SECT6  notype ()    External     | _SetInitParam
>     tag index 0000003E size 000000B0 lines 00000BD9 next function
> 00000049

Ok, so the library has the function declared as __cdecl.  In the function
prototype, is it explicitly written as __cdecl?  Was the library compiled
with /Gd?

Assuming you're still getting the same error you originally posted, the
caller is expecting __stdcall.  Was the caller compiled with /Gz?

Normally the solution to this kind of problem is one of two things:  Either
consistently use /Gd or consistently use /Gz or consistenly use neither.
Or, modify the function delcaration in the header to explicitly specifiy the
calling convention.  e.g.

void __cdecl SetInitParam(...);

-cd



Tue, 06 Sep 2005 22:16:52 GMT  
 Problem linking a VC generated static LIB into a win32 DLL project
Using your suggestion of declaring as __cdecl explicitly worked.
extern int __cdecl SetInitParam(blah blah);

To make the DLL compatible with say VB I ended up making wrappers for
each function I need to use.  I.e.,

In the DLL project:
extern int __cdecl SetInitParam(blah blah);

int __stdcall SetInitParamA(blah blah);

int __stdcall SetInitParamA(blah blah)
{
  return(SetInitParam(blah blah));

Quote:
}

Then put SetInitParamA in the def file to export.  A lot of work for
each function, but it seems to work.

Thanks much for your help!

Tim


Quote:

> > Thanks for your reply.

> > Below is the output from dumpbin on the lib.
> > 028 00000000 SECT6  notype ()    External     | _SetInitParam
> >     tag index 0000003E size 000000B0 lines 00000BD9 next function
> > 00000049

> Ok, so the library has the function declared as __cdecl.  In the function
> prototype, is it explicitly written as __cdecl?  Was the library compiled
> with /Gd?

> Assuming you're still getting the same error you originally posted, the
> caller is expecting __stdcall.  Was the caller compiled with /Gz?

> Normally the solution to this kind of problem is one of two things:  Either
> consistently use /Gd or consistently use /Gz or consistenly use neither.
> Or, modify the function delcaration in the header to explicitly specifiy the
> calling convention.  e.g.

> void __cdecl SetInitParam(...);

> -cd



Wed, 07 Sep 2005 09:20:53 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Changing project configuration for a Win32 Static Lib Project

2. Problems exporting class in static lib from a Win32 DLL when a copy constructor is defined

3. Linking problem on a migrated VC6 Win32 DLL project

4. Linking problem: missing .lib file from dll project

5. Static library using MFC called from Win32 application linked with nafxcwd.lib

6. Trouble linking Win32 Static lib with MFC exe

7. New vs.net static library project generates LINK errors

8. New vs.net static library project generates LINK errors

9. DLL Linking error (VC project problem)

10. Converting DLL project to static lib

11. VC 4.2 link error linking static libraries from VC 6.0

12. Linking a static Lib to a DLL

 

 
Powered by phpBB® Forum Software