For Programmers: Free Programming Magazines  


Home > Archive > VC Language > November 2005 > Static library problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Static library problem
Rasmus Oudal Edberg

2005-11-23, 7:04 pm

Hi,

I have a problem with static libraries in Visual Studio 2003.
My problem is the following:

I have project 'BaseFramework' which is a static library(.lib) project,
this project uses some C functions from a vendor.

I also have a project B which is an application(.exe) project,
this project includes the a.lib file.

The 'BaseFramework' project builds just fine, but my problem is that when I
try to build project B I get a lot LNK2019 errors saing that
the linker cannot resolve the C functions that the 'BaseFramework' project
is using, like this:

BaseFramework.lib(InetAddress.obj) : error LNK2019: unresolved external symbol
_htonl@4 referenced in function "public: __thiscall BaseFramework::Wrapper::Net::InetAddress
::InetAddress(unsigned
short)" (?? 0InetAddress@Net@Wrapper@BaseFramework@@
QAE@G@Z)

Does anybody have clue as to what I should do?

/Regards

Rasmus


Igor Tandetnik

2005-11-23, 7:04 pm

Rasmus Oudal Edberg <rasmus@NOSPAMstudentz.dk> wrote:
> I have project 'BaseFramework' which is a static library(.lib)
> project, this project uses some C functions from a vendor.
>
> I also have a project B which is an application(.exe) project,
> this project includes the a.lib file.
>
> The 'BaseFramework' project builds just fine, but my problem is that
> when I try to build project B I get a lot LNK2019 errors saing that
> the linker cannot resolve the C functions that the 'BaseFramework'
> project is using, like this:


When you build a static library, it does _not_ incorporate its
dependencies - it just refers to them. In other words, the static
library is not processed by the linker.

When you then build the final module (an EXE or a DLL) you have to
explicitly link against your static library and all its dependencies.
One way to do this is to put the following line in some header file that
every user of your static library must include:

#pragma comment( lib, "theother.lib" )

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com