VS2019配置跨平台win-linux开发

VS2019配置跨平台win-linux开发_第1张图片

VS2019配置跨平台win-linux开发_第2张图片

在这里,悬着gdb就行了,gdbserver需要在linux端安装.

 

VS2019配置跨平台win-linux开发_第3张图片

VS2019配置跨平台win-linux开发_第4张图片 

 

调试->选项->跨平台

 

VS2019配置跨平台win-linux开发_第5张图片

 

 

最后,如果不行,在关掉当前项目,新建个linux空项目.

提供一段测试代码:

test1:

#include 
#include 
#include 
#include
#include 
#include
#include 
#include 
#include
#include 
#include 
#include
#define MAX_EVENTS 10
struct epoll_event ev, events[MAX_EVENTS];
int listen_sock, conn_sock, nfds, epollfd;
char* response = "HTTP/1.1 200 OK\r\nContent-Type:text/html\r\nContent-Length:14\r\n\r\n

hello

"; /* Set up listening socket, 'listen_sock' (socket(), * * bind(), listen()) */ void do_use_fd(int fd) { send(fd, response, strlen(response), 0); close(fd); } bool setnonblocking(int fd, bool flag) { int fmode = 0; if (-1 == (fmode = fcntl(fd, F_GETFL, 0))) { return false; } if (flag) fmode &= (~O_NONBLOCK); else fmode |= O_NONBLOCK; if (-1 == fcntl(fd, F_SETFL, fmode)) return false; return true; } int main(int argc, char** argv) { short PORT = 9999; if (argc == 2) { PORT = atoi(argv[1]); } listen_sock = socket(AF_INET, SOCK_STREAM, 0); if (-1 == listen_sock) { return -1; printf("call listen faild."); } //设置地址复用 int val = 1; if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)) < 0) { perror("setsockopt()"); } sockaddr_in local = { 0 }; socklen_t addrlen = sizeof(local); sockaddr_in saddr; saddr.sin_family = AF_INET; saddr.sin_port = htons(PORT); saddr.sin_addr.s_addr = inet_addr("0.0.0.0"); int ret = bind(listen_sock, (sockaddr*)& saddr, sizeof(saddr)); if (0 != ret) { std::cout << "failed to bind" << std::endl; return -2; } listen(listen_sock, 20); epollfd = epoll_create(10); if (epollfd == -1) { perror("epoll_create"); exit(EXIT_FAILURE); } ev.events = EPOLLIN; ev.data.fd = listen_sock; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) { perror("epoll_ctl: listen_sock"); exit(EXIT_FAILURE); } for (;;) { nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1); if (nfds == -1) { perror("epoll_pwait"); exit(EXIT_FAILURE); } for (int n = 0; n < nfds; ++n) { if (events[n].data.fd == listen_sock) { conn_sock = accept(listen_sock, (struct sockaddr*) & local, &addrlen); if (conn_sock == -1) { perror("accept"); exit(EXIT_FAILURE); } setnonblocking(conn_sock, true); ev.events = EPOLLIN | EPOLLET; ev.data.fd = conn_sock; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock, &ev) == -1) { perror("epoll_ctl: conn_sock"); exit(EXIT_FAILURE); } } else { do_use_fd(events[n].data.fd); } } } return 0; }

VS2019配置跨平台win-linux开发_第6张图片 

你可能感兴趣的:(c/c++,linux,网络编程)