C语言 如何在Linux中使用Windows套接字编译程序



我有一个用C编写的程序,它使用以下库:

#ifdef _WIN32
#include <winsock2.h>
#define socklen_t int
#else
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Windows中,为了使用gcc编译该程序,您必须使用-lWs2_32属性。

如何在 Linux 中使用 gcc 编译它?

-lWs2_32是一个链接器选项,用于指定要链接的库。编译器不使用它。

对于 Linux 下的 gcc,在使用套接字函数时无需显式指定库。

我认为您应该静态链接可执行文件并使用MinGW。但这只是一个假设。从来没有尝试过。

-lWs2_32 是一个链接器选项,用于指定要链接的库。编译器不使用它。

对于 Linux 下的 gcc,在使用套接字函数时无需显式指定库。

最新更新