0

I'm trying to build WolfSSL, which uses the CryptAcquireContext function of the Windows API. I'm trying to build it using 'cl.exe'. I don't want to use 'nmake.exe' nor 'MSBuild.exe', just plain 'cl.exe'.

If I use Visual Studio for building, I can set the <PlatformToolset>v120</PlatformToolset> parameter in the 'vcxproj' file, which defines the platform toolset version. With this option set, Visual Studio compiles and links the code without error.

If I try compiling and linking with 'cl.exe', I get the following message:

error LNK2019: unresolved external symbol __imp__CryptAcquireContextA@20

Since Visual Studio succeeds, the problem is not caused by a missing SDK.

The documentation for 'cl.exe' does not include any information on platform toolset. I tried adding /p:PlatformToolset=v120, as suggested here, but it seems only MSBuild accepts this option.

Though the description of my problem is long, my question is simple. How do I define the platform toolset for 'cl.exe'?

-- EDIT --

adding Advapi32.lib after the \link option fixed the linking problem.

However does that mean I have to instruct the linker to use every native Windows '.lib' file I use? I don not have to do that for the standard library. Is there a way to force cl to include all native Windows '.lib' files automatically, just like it does with the standard library?

LordCapybara
  • 117
  • 2
  • 11
  • your problem in very poor knowledge. you even not understand difference between compiling and linking. and read msdn page for `CryptAcquireContext` - the word `Advapi32.lib` nothing say for you ? – RbMm Sep 10 '17 at 16:53
  • Yes, I do understand the difference between compiling and linking. But 'ln' does both, correct? I tried adding `Advapi32.lib` after the `\link` option. The code linked fine. However does that mean I have to include every native Windows '.lib' file I use? I don't have to do that for the standard library. Is there a way to force `cl` to include all these files at once? – LordCapybara Sep 10 '17 at 17:04
  • you need include all `.lib` files from which you import direct. – RbMm Sep 10 '17 at 17:09
  • 1
    Such are the advantages of using an IDE. When you create a new project then it by default already provides the link instructions for several common Windows libraries. Like kernel32.lib, user32.lib, gdi32.lib. And yes, advapi32.lib. When you do it by hand then you have to type them in yourself. At least consider using msbuild.exe. The toolset is selected by the Visual Studio Command prompt you used to initialize the environment, it sets the LIB variable. – Hans Passant Sep 10 '17 at 17:57
  • Thanks Hans Passant! I assumed 'cl' would link Windows libraries by default or by addind a simple CLI option. I guess using MSBuild would be simpler after all... – LordCapybara Sep 10 '17 at 21:20

0 Answers0