4
votes

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

4
you should probably show us the makefile/project file and the linker errors. And +1 for all the answers to update your visual studio edition... Good lord, 5.0 is ancient.Tim

4 Answers

3
votes

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.
   }
2
votes

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.

1
votes

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.

0
votes

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.