cwindowsvisual-studiodriverkmdf

Why am I getting Error LNK2019 unresolved external symbol when calling a function which is statically linked?


I've built a statically linked library from a project which I downloaded from here InfinityHook project I'm getting the following two (2) errors in Visual Studio 2017 when I reference any of the functions which are available for export.

Error LNK2019 unresolved external symbol IfhInitialize referenced in function DriverEntry HelloWorld_Driver C:\Users\MYSELF\Documents\Visual Studio 2017\Projects\HelloWorld_Driver\HelloWorld_Driver\Driver.obj

Error LNK1120 1 unresolved externals HelloWorld_Driver C:\Users\MYSELF\Documents\Visual Studio 2017\Projects\HelloWorld_Driver\x64\Debug\HelloWorld_Driver.sys

I get the same type of error when I reference another function from the same infinityhook.h header file and which is statically built in the libinfinityhook.lib file. So basically none of the functions that are "exported" are available to be called and are giving linking errors when referenced from the main project. Before arriving at this conclusion I tried several possible solutions found on StackOverflow but none of them have worked. I've added the statically linked file libinfiinityhook.lib in Visual Studio 2017 Configuration Properties->Linker->Input->Additional Dependencies and the file is located in the correct directory on disk so the linker can find it. But I also added the directory path to this library file to the following settings in VS2017 Configuration Properties->Linker->General->Additional Library Directories.


Solution

  • If anyone else is having the same issue the problem was that I was calling the two C++ defined functions, declared as C++ functions from a "C" based module. Recompiled the static library with the keyword extern and all is working as it should.