我正在将我在Borland写的一个voip应用程序移植到Mingw,所以我知道代码可以工作。我使用命令行gcc -lws2_32 -mwindows voipapp.c -o voipapp
并继续收到错误消息
未定义引用'WSAAsyncSelect @ 16'“。
它似乎正确定位libws2_32.a
,因为没有错误消息告诉我。什么可能是错的任何想法?我安装了mingw的最新版本之一。谢谢!
我的代码如下:
#include <windows.h>
#include <winsock2.h>
#define __MT__
#include <mmreg.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <process.h>
#define WM_SOCKETREAD (WM_USER + 1)
SOCKET ListenSocket;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow) {
static char szAppName[] = "voip";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(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.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClassEx(&wndclass);
hwnd = CreateWindow(szAppName, "VOIP prototype",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
WSAAsyncSelect(ListenSocket, hwnd, WM_SOCKETREAD, FD_READ|FD_CLOSE);
while ( GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
答案 0 :(得分:1)
您必须指定正确的链接顺序。
尝试:
gcc voipapp.c -o voipapp -mwindows -lws2_32