在命令行上使用Visual Studio进行编译时如何包含库? [英] How to include libraries when compiling with Visual Studio on command line?
问题描述
我正在尝试在命令行上使用Visual Studio 2008构建程序。
阅读演练:在命令行上编译本机C ++程序一个>。
我尝试了以下操作:
I'm attempting to build a program with Visual Studio 2008 on the command line. After reading Walkthrough: Compiling a Native C++ Program on the Command Line. I tried the following:
运行vcvaralls.bat来设置环境:
Run the vcvaralls.bat to setup the enviroment:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
编写此简单的C ++应用程序:
Wrote this simple C++ application:
#define _WIN32_WINNT 0x501
#include <windows.h>
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBoxA(0,"Hello","Hello",MB_OK);
return 0;
}`
并尝试对其进行编译:
cl /EHsc /GA simple.cpp
发生这种情况:
/out:simple.exe
simple.obj
simple.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16
simple.exe : fatal error LNK1120: 1 unresolved externals
这使我相信我需要包括user32.lib或类似内容。
我无法从Visual Studio手册中弄清楚该怎么做。
Which leads me to believe that I need to include user32.lib or similar. I cant figure out from the visual studio manuals how to do that.
推荐答案
是的,要使用MessageBox,您需要至少与User32.lib链接,如此处。使用:
Yes, to use MessageBox you need to link at least with User32.lib, as shown here . Use:
cl /EHsc /GA /MT simple.cpp User32.lib
/ MT选择运行时库。在此示例中,我使用了多线程静态库。
/MT chooses the Run-time library. In this example I used multi-threaded static library.
这篇关于在命令行上使用Visual Studio进行编译时如何包含库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!