views:

166

answers:

4

I am using Visual Studio 5.0 I have DLL and a static library . My intention is to use a static function that is defined in the static library . I have included the header file in the intended source cpp and also given the path in the project dependencies . Still it gives me linker errors .

Following is the linker error

error LNK2019: unresolved external symbol "public: static bool __cdecl gph::IsA(class PtOnDemand &,wchar_t const *)" (?IsA@gph@@SA_NAAVPtOnDemand@@PB_W@Z) referenced in function "private: int __thiscall PtXMLP::HandleObjectBegin(char const *,char const * *)" (?HandleObjectBegin@PtXMLP@@AAEHPBDPAPBD@Z) 1>.\ReleaseU/epptxml.dll : fatal error LNK1120: 1 unresolved externals

Any suggestions

A: 

First of all, its time to get a new version of Visual Studio :-) But its likely that you are using it for legacy support.

Anyway, just including the header file isn't enough. You also need to make sure you tell the linker where the static library file is (should be a .a file perhaps) and what the name of the library is.

Fuzz
@fuzz I have already done that
sameer karjatkar
A: 

Well, I don't know exactly about Visual Studio 5. But you have to add the library that you want to link statically as additional dependency to your project.

Simon Linder
@simon I have already done that
sameer karjatkar
+2  A: 

You also have to include the lib file to your project in order for it to be linked in. Note sure about VS5 but on 6 this is under Project / Add to Project / Files. Alternatively, you could include it under linker options in your project properties.

Shane MacLaughlin
@shane I have already done that
sameer karjatkar
@Sameer, sounds like you should be investigating jdv's answer so. Have a look at the effect of addding _MBCS and UNICODE as preprocessor definitions
Shane MacLaughlin
+2  A: 

It could be that the linker is not finding your function because it is compiled with different settings. Like release vs debug, unicode vs non-unicode, differences in calling conventions. That may cause the name to be mangled differently. If the .h file is written in c, not c++, you might need to disable name mangling altogether by wrapping the prototypes in

  extern "C" 
   {
     // function prototypes go here.
   }
jdv
+1: Based on Sameer's comments to other answers, this is almost certainly the case.
David Gladfelter
+1, as above, given the function in question takes a wchar_t indicating unicode. Also IsA sounds like a IsKindOf type function common in MFC (e.g. RTTI substitute)
Shane MacLaughlin