gynvael/random-stuff

Trying to compile with CL,

CaledoniaProject opened this issue · 3 comments

Hi there,

I'm using VS 2012 on Windows 8. To link against kernel32 I've added the following line to history.cc

#pragma comment(lib, "kernel32.lib")

And cl still complains about symbols,

cmd> cl history.cc /DUNICODE /EHsc

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

history.cc
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:history.exe
history.obj
history.obj : error LNK2019: unresolved external symbol _GetConsoleCommandHistor
yLengthA referenced in function _main
history.obj : error LNK2019: unresolved external symbol _GetConsoleCommandHistor
yA referenced in function _main
history.exe : fatal error LNK1120: 2 unresolved externals

Can you help?

Ah, the only function exported in kernel32 is GetConsoleHistoryInfo, am I wrong?

Both functions are undocumented, so I wouldn't really expect them to be exported in a .lib file - that's why I suggested in the comment to link directly against kernel32.dll. That being said, I don't think cl/link can actually do that - it's a gcc/ld feature.

So I guess the proper way to correct this is dynamic linking, i.e. using GetModuleHandle and GetProcAddress to resolve the addresses of these functions.

Make sense