Windows编程常见错误(1) 之 undefined reference to ***
来源:互联网 发布:淘宝热销类目排行 编辑:程序博客网 时间:2024/06/06 07:08
源代码如下:
/*------------------------------------------------------------ HELLOWIN.C -- Displays "Hello, Windows 98!" in client area (c) Charles Petzold, 1998 ------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE: PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}
1、未创建项目,以单独的C文件存在时报如下错误。
2、创建Win32 GUI project
3、运行项目,报如下错误:
4、添加如下图设置,链接动态库:
Settings→Compiler..→Linker settings
库文件路径:E:\Program Files (x86)\CodeBlocks\MinGW\lib
5.至此,编译成功。运行结果如下:
0 0
- Windows编程常见错误(1) 之 undefined reference to ***
- C++编程错误 : undefined reference to `vtable for Student'
- 错误:undefined reference to `__gxx_personality_v0'
- undefined reference to 链接错误
- undefined reference to `clock_nanosleep' 错误
- undefined reference to 'pthread_create' 错误
- 错误:undefined reference to `__gxx_personality_v0' .
- NDK undefined reference to 错误
- undefined reference to错误原因
- 错误:undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'
- undefined reference to 'socket' 错误
- undefined reference to gettid() 错误
- undefined reference to `SSL_library_init'错误
- undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'错误
- Qt编程遇到的坑之undefined reference to
- 编译错误:undefined reference to `vtable for
- QT错误:undefined reference to `WinMain@16'
- 编译错误undefined reference to `dlsym'
- OpenCV的智能指针: Ptr
- 潘鹏整理WPF(15)样式基础
- opencv为图像画框并显示文字
- Java线程同步中关键字synchronized简述
- 设备控制接口(ioctl 函数) 主要是在驱动中
- Windows编程常见错误(1) 之 undefined reference to ***
- ROS代码经验系列-- tf进行位置查询变换
- Linux下PCIe驱动以及DMA机制
- centos7安装jdk1.7(rpm)
- 【数据结构与算法】——插入排序
- centos6.5下安装redmine或迁移
- MFC框架各部分指针获取方式
- 第七周项目(6):停车场模拟
- NSString,NSData,std::string,const char*相互转化