简体   繁体   中英

How to compile program with windows sockets in linux?

I have a program written in C which uses the following libraries:

#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>

In Windows , in order to compile this program with gcc , you had to use -lWs2_32 property.

How to compile it using gcc in linux ?

-lWs2_32 is a linker option to specify a library to link. The compiler does not use it.

For gcc under Linux there is no need to explicitly specify a library when using socket functions.

I think you should statically link the executable and use MinGW. But it's just an assumption. Never tried it.

-lWs2_32 is a linker option to specify a library to link. The compiler does not use it.

For gcc under Linux there is no need to explicitly specify a library when using socket functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM