简体   繁体   English

C程序中的链接器错误

[英]Linker error in c program

I am trying to code c program that uses Win32 api to display message box, but i am getting this linker error. 我正在尝试对使用Win32 api来显示消息框的c程序进行编码,但出现此链接器错误。 How could it be resolved? 如何解决?

code : 代码:

#include<windows.h>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevsInstance,LPSTR SZCmdLine,int iCmdShow)
{
    MessageBox(NULL,TEXT("hello"),TEXT("this is me"),MB_ICONEXCLAMATION |  MB_OK);
   return 0;
}

error: 错误:

1>------ Build started: Project: winfirstprog, Configuration: Debug Win32 ------
1>Compiling...
1>winfirstprog.cpp
1>Linking...
1>winfirstprog.obj : error LNK2028: unresolved token (0A000030) "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>winfirstprog.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>F:\my_doc\C programming Prog & Documentation\Data structure in c\STARTOVER\winfirstprog\Debug\winfirstprog.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://f:\my_doc\C programming Prog & Documentation\Data structure in c\STARTOVER\winfirstprog\winfirstprog\Debug\BuildLog.htm"
1>winfirstprog - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Getting started with the correct project template is 99% of the Hello World problems. 正确的项目模板入门是99%的Hello World问题。 You didn't, this code got compiled by the C++/CLI compiler. 您没有,该代码是由C ++ / CLI编译器编译的。 File + New Project and select the Win32 + Win32 Project template. File + New Project,然后选择Win32 + Win32 Project模板。 – Hans Passant –汉斯·帕桑(Hans Passant)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM