0

We have a Visual Studio 2015 driver project. For various reasons, we use "make" (the unix tool, built for windows) to build our entire product. It is also preferred to use make to build the windows-only components (keeps the build process consistent).

Running Server 2012R2, VS 2015 Update 3, DDK 10 and SDK 10.

The project builds fine in VS2015 and the driver works, so, the codebase is good.

I enabled the verbose build output and captured that to analyze what VS is doing to build the project (the driver is simply a bunch of C files, does not appear to be anything too earth-shatteringly unique). The VS build sets LIB, LIBPATH and INCLUDE variables, then issues a "cl.exe" command to build, followed by a "link.exe" command to link. There are also commands to build the message file (mc.exe) and resource file "rc.exe". I captured all of these commands and incorporated them into a makefile.

I can get the project to compile but, my problem is with the link phase. I will show the error in a few lines. I have tried simply running the commands (from the log) by themselves in a "VS2015 x64 Native Tools Command Prompt" (%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64) and I get the same error.

When I link, I get:

LINK : error LNK2001: unresolved external symbol GsDriverEntry
os_win.obj : error LNK2001: unresolved external symbol __stdio_common_vsprintf
winbuild\x64\Win7Release\driver.sys : fatal error LNK1120: 2 unresolved externals

I had to make one change from the cl.exe command line that VS logged, which was to specify /GS- (VS enabled the option). Otherwise, when I run the compile and link comands, I get a bunch of additional errors:

os_win.obj : error LNK2001: unresolved external symbol __security_cookie

So, Googling the vsprintf error, I came across suggestions to link with legacy_stdio_definitions.lib to access those functions, but that did not work (and using cygwin's nm.exe to examine the lib, showed that the vsprintf functions are Undefined.

If I build from the makefile, I lose the error about GsDriverEntry being undefined but I still have the vsprintf errors.

I tried also removing the /nodefaultlib link option... no effect.

So, I am at a complete loss as to what is going on. It makes no sense to me that, VS can build the project, but I cannot, using the same commands. What details or concept am I missing?

My link command line:

link /OUT:Win7Release/driver.sys \
/NOLOGO /INCREMENTAL:NO /IGNOREIDL /OPT:ICF /MAP /SUBSYSTEM:CONSOLE /OPT:REF \
/PDB:none /MACHINE:X64 /MANIFEST:NO /WX /PROFILE /kernel /Driver /RELEASE \
/VERSION:"10.0" /osversion:10.0 /ENTRY:"GsDriverEntry" \
/IGNORE:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221,4108,4088,4218,4218,4235 \
/ERRORREPORT:PROMPT /MERGE:"_TEXT=.text;_PAGE=PAGE" /SECTION:"INIT,d" \
/IMPLIB:"Win7Release/driver.lib" /SUBSYSTEM:NATIVE",6.01" \
.. list of obj files .. \
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib \
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
legacy_stdio_definitions.lib ntoskrnl.lib hal.lib wmilib.lib BufferOverflowK.lib
Jon
  • 1,675
  • 26
  • 57

1 Answers1

1

Okay, well, I found this post, which helped me earlier this year with another similar problem... seems that vsprintf is also declared inline, now. Setting _NO_CRT_STDIO_INLINE as /D option to cl.exe allows the code to build AND link.

So.. why would the Visual Studio 2015 project build properly? That define is NOT in the build output.

Community
  • 1
  • 1
Jon
  • 1,675
  • 26
  • 57
  • It's fine to answer your own question but if you want another question answered it needs to be another question. – Mike Kinghan Dec 10 '16 at 17:14
  • When you captured the commands from the _VS_ build, did you also capture the shell environment strings present when the tools ran? `cl.exe` and `link.exe` are sensitive to quite a few of those. – bobbogo Dec 15 '16 at 12:38