Question

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.

Was it helpful?

Solution

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

OTHER TIPS

If you are using visual stdio, check your project property vs your friend's project property and check link library path+ library name with .lib shoul be included. It seems in your friends computer is not getting the library to resolve the symbols. Compile time checking is done only with header files. While linking it should find the definition of yor function in library.

for command line: from:http://social.msdn.microsoft.com/Forums/vstudio/en-US/6bcae3d1-85b6-471d-a4ee-7b455b21460b/how-do-i-link-libraries-that-are-sitting-in-different-directories-from-the-command-line?forum=vcgeneral

cl main.obj ab1.lib ab2.lib de1.lib de2.lib gh1.lib /Fetestmain.exe /link /LIBPATH:C:\test\ab /LIBPATH:C:\test\de /LIBPATH:C:\test\gh

The "/link" is very important...do not use "/LINK", the uppercase LINK is not recognised.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top