cpp文件不使用cl编译,但在Visual Studio中编译得很好
cpp File not compiling with cl, but compiles just fine inside Visual Studio
我遇到了一个问题,无法使用CL(VS CMD)编译以下代码。它没有编译,而是给了我错误LN2019。在VS中编译相同的代码,编译时没有错误。
#include <windows.h>
LRESULT CALLBACK
MainWindowCallback( HWND Window,
UINT Message,
WPARAM WParam,
LPARAM LParam)
{
LRESULT Result = 0;
switch(Message)
{
case WM_SIZE:
{
OutputDebugStringA("WM_SIZEn");
} break;
case WM_DESTROY:
{
OutputDebugStringA("WM_DESTROYn");
} break;
case WM_CLOSE:
{
OutputDebugStringA("WM_CLOSEn");
} break;
case WM_ACTIVATEAPP:
{
OutputDebugStringA("WM_ACTIVATEAPPn");
} break;
default:
{
// OutputDebugSTringA("defaultn")
Result = DefWindowProc(Window, Message, WParam, LParam);
} break;
}
return(Result);
}
int CALLBACK
WinMain(HINSTANCE Instance,
HINSTANCE PrevInstance,
LPSTR CommandLine,
int ShowCode)
{
WNDCLASS WindowClass = {};
WindowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
WindowClass.lpfnWndProc = MainWindowCallback;
WindowClass.hInstance = Instance;
// WindowClass.hIcon;
WindowClass.lpszClassName = "FooWindowClass";
return(0);
}
我追踪到第36行的问题:
Result = DefWindowProc(Window, Message, WParam, LParam);
当我把这行注释出来时,文件编译得很好。用于编译的cl命令也是相当标准的:
cl -Zi Foo.cpp
我遗漏了一些cl参数吗?
您必须链接到user32.lib:
cl Foo.cpp user32.lib
错误Error LN2019
没有"main"(您似乎已将其命名为WinMain
)。
另请参阅:错误LNK2019:函数__mainCRTStartup 中引用的未解析外部符号_main
相关文章:
- 如何在 Android Studio 4 中编译 C/C++ 原生代码
- 编译并运行后,输出未出现在 Visual Studio 代码中
- 第三方 API 中的编译错误 - Visual Studio
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 如何在 CMake 中添加预编译标头用于 Visual Studio 生成器
- 如何在调试中使用Visual Studio正确编译WebRTC?
- 如果我的手机是 ARMv8,为什么 Android Studio 会C++编译为 ARMv7?
- Qt Visual Studio 2015 加载项编译问题
- 通过命令行在Visual Studio中编译单个独立文件
- 使用 Visual Studio 2019 编译 Unicode
- C++20 使用 Visual Studio 编译模块:不编译或导入 ixx 文件
- 使用 CMake 和 Visual Studio 2019 编译 GLEW?
- Visual Studio 2019编译和构建
- 如何在不需要LIBCD.lib的情况下在Visual Studio 6中编译C项目
- 在Visual Studio中编译C++
- Qt - 为什么Visual Studio 2019在qml资源中添加10Mb文件后无法再编译我的项目?
- 如何获得CMake Tools以在Visual Studio Code中编译具有C++11(或更高版本)功能的程序?
- 如何在Visual Studio 2019中启用C++98编译?
- 在 Visual Studio 中的 1 个项目中编译单个 C++ 源文件
- 如何在Visual Studio中为CUDA项目启用单独的编译