Link the static library to the DLL

I am using Visual Studio 5.0. I have a DLL and a static library. My intention is to use the static function defined in the static library. I included the header file in the alleged cpp source, and also gave the path in the project dependencies. However, this gives me linker errors.

Below 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 by the function "private: int __thiscall PtXMLP :: HandleObjectBegin (char const *, char const * *) "(? HandleObjectBegin @PtXMLP @@ AAEHPBDPAPBD @Z) 1>. \ ReleaseU / epptxml.dll: fatal error LNK1120: 1 unresolved external

Any suggestions

+3
source share
4 answers

The linker may not find your function, because it is compiled with various settings. Like the release of vs debug, unicode vs non-unicode, differences in calling conventions. This can lead to the fact that the name will be distorted in different ways. If the .h file is written in c rather than C ++, you may need to completely disable name management by wrapping prototypes in

  extern "C" 
   {
     // function prototypes go here.
   }
+3
source

You must also include the lib file in your project so that it is linked. Pay attention to VS5, but at 6 this is in Project / Add to Project / Files. In addition, you can include it in the linker options in the project properties.

+2
source

, Visual Studio 5. , .

+1

First of all, it's time to get the new version of Visual Studio :-) But most likely you are using it to support older versions.

In any case, simply including the header file is not enough. You also need to make sure that you specify the linker where the static library file is (there must be a .a file) and the library name.

0
source

Source: https://habr.com/ru/post/1732856/


All Articles