linux使用mingw32交叉编译socket程序入门

1:编译环境,安装合适的mingw编译链
apt-cache search mingw
apt-get install gcc-mingw-w64-x86-64
2:linux和windows的一些接口区别:
https://blog.youkuaiyun.com/zhangbohh8662/article/details/62044538
3:头文件:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <wchar.h>


#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/time.h>
#include <sys/stat.h>


#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib,"ws2_32.lib")

4:mingw32编程时fwrite写文件时自动多了0X0D
https://blog.youkuaiyun.com/shen_001/article/details/8750748
5:write发送socket数据时,发不出去,得使用send
6:fopen文件时,文件中不能包含特殊字符,否则fopen失败,如: > / \ | : " * ?
6:编译指令:
x86_64-w64-mingw32-gcc -o tcp_client.o -g tcp_client.c
x86_64-w64-mingw32-gcc tcp_client.c -lws2_32 -lpthread -lm

了解更多

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值