我如何编译使用CL一个Window API的程序? [英] How do I compile a Window API program using cl?

查看:198
本文介绍了我如何编译使用CL一个Window API的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译使用Windows SDK命令提示一个简单的C Windows API的程序。

下面从程序的摘录:

 的#include<&WINDOWS.H GT;
INT WINAPI的WinMain(HINSTANCE的hInstance,HINSTANCE ^ h prevInstance,LPSTR lpCmdLine,诠释的nCmdShow)
{[...]    的RegisterClass(安培; WC);
    HWND = CreateWindow的(测试,NULL,0,0,0,0,0,NULL,NULL,的hInstance,NULL);[...]

当我使用编译

  CL test.c的

在Windows SDK命令PROMT,它给了我很多像这样的链接器错误的:

  test.obj:错误LNK2019:​​函数WinMain中引用解析的外部符号__imp_CreateWindowExA
test.obj:错误LNK2019:​​解析外部符号__imp_RegisterClassA函数WinMain中引用


解决方案

这些功能生活USER32.LIB。您需要提供了对CL工具。

  CL test.c的C:\\ Program Files文件\\微软的SDK \\ WINDOWS \\ v6.0A \\ LIB \\ USER32.LIB
微软(R)32位C / C ++优化编译器版本15.00.307
版权所有(C)微软公司。版权所有。test.c的
微软(R)增量链接器版本9.00.30729.01
版权所有(C)微软公司。版权所有。/out:test.exe
test.obj
C:\\ Program Files文件\\微软的SDK \\ WINDOWS \\ v6.0A \\ LIB \\ USER32.LIB

I am trying to compile a simple C Windows API program using the Windows SDK Command Prompt.

Here an excerpt from the program:

#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

[...]

    RegisterClass(&wc);
    hwnd = CreateWindow("test", NULL, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);

[...]

When I compile it using

cl test.c

in the Windows SDK Command Promt, it gives me a lot of linker errors like these:

test.obj : error LNK2019: unresolved external symbol __imp_CreateWindowExA referenced in function WinMain
test.obj : error LNK2019: unresolved external symbol __imp_RegisterClassA referenced in function WinMain

解决方案

Those functions live in user32.lib. You need to supply that to the cl tool.

cl test.c ""C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\user32.lib"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.307
Copyright (C) Microsoft Corporation.  All rights reserved.

test.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\user32.lib"

这篇关于我如何编译使用CL一个Window API的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆