c - 如何在 linux 中使用 windows sockets 编译程序?

标签 c linux windows sockets gcc

我有一个用 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,使用套接字函数时无需显式指定库。

关于c - 如何在 linux 中使用 windows sockets 编译程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22019989/

相关文章:

c - 两个数相加

linux - 在 linux 中写入后崩溃

java - JDK 8 在 Linux 上随机崩溃

c++ - Windows 控制台代码页 866

c - 将数据写入二进制文件,然后读回

c - 有没有办法检查空终止字节后的字符串内容?

c - 如何在 bash 脚本中调用 C 程序并将其返回值存储到变量中?

c - 如何在 C 中调试 Windows 服务启动代码,而不是 C#

c++ - 在某些特殊情况下,Win32 ShowWindow api 在 Windows 7 SP1 上的行为是否不同?

c - 如何正确终止信号处理程序中的线程?