Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker error while linking some windows APIs

I have a makefile project in my system. Recently, I added some new functions which makes use of the following Windows APIs:

RegOpenKeyEx
RegEnumKeyEx
RegCloseKey
RegGetValue

For having those APIS I added the windows.h header file as well. The code compiles and links fine in my machine. But, linking fails in my colleagues machine. We all are working on 64 bit windows machine. In his PC I get the error:

error LNK2001: unresolved external symbol __imp_RegOpenKeyExW

error LNK2001: unresolved external symbol __imp_RegGetValueW

error LNK2001: unresolved external symbol __imp_RegCloseKey

error LNK2001: unresolved external symbol __imp_RegEnumKeyExW

What I tried: Since the library being used was Advapi32.lib in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64

I tried adding following line:

LINKFLAGS += -L "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64"

I added the path of the library to environment variable PATH

I copied the lib to the output folder.

Nothing worked.

As I said earlier, the code works fine in my PC but fails in another one.

like image 322
sajas Avatar asked Apr 30 '26 03:04

sajas


1 Answers

The registry functions require you to pass Advapi32.lib to the linker. This is the step that you have missed.

like image 65
David Heffernan Avatar answered May 01 '26 16:05

David Heffernan