Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to statically link the library for using SHGetSpecialFolderPath using cl.exe

Tags:

c++

winapi

I am using the SHGetSpecialFolderPath function of the WINAPI, and also using the windows VisualExpressC++ compiler (cl.exe) to compile it. But when in linking stage I get this error:

error LNK2019: unresolved external symbol __imp___SHGetSpecialFolderPathA@16 referenced in function _main

I guess that I need to link Shell32.lib, is this correct and how would I do it in a way that I can actually get my program running on another system, maybe even a XP instead of a 7, without recompiling it?

like image 542
Sim Avatar asked Jan 18 '23 06:01

Sim


1 Answers

If you're compiling from the command line, just add shell32.lib to the command, something like this:

cl file1.cpp file2.cpp shell32.lib

You're just using a function that Windows provides. Since this particular function goes back almost to the dawn of time (Windows 95, if I recall correctly), you shouldn't have to do anything special to use it on anything reasonably current.

like image 70
Jerry Coffin Avatar answered Jan 20 '23 19:01

Jerry Coffin