日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Visual Studio 2017开发linux程序使用实例及原理简析

發(fā)布時(shí)間:2025/3/21 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Visual Studio 2017开发linux程序使用实例及原理简析 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.下載安裝vs開發(fā)linux程序的工具包


2.創(chuàng)建一個(gè)工程,選擇跨平臺(tái)里面的linux平臺(tái)


3.寫一段測(cè)試代碼,這里就可以包含linux的系統(tǒng)頭文件編譯,不過vs下還是現(xiàn)實(shí)紅的

#include <cstdio> #include <stdlib.h> #include <stdio.h> #include <string.h>#include <iconv.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/file.h> #include <unistd.h> #include <sys/mman.h> #include <fcntl.h>#include <string> #include <iostream> #include <istream> #include <iosfwd> #include <sstream> #include <fstream> using namespace std;int fd_ = 0; int size_ = 0; char *buff_ = nullptr;void open_file(std::string file_name) {fd_ = open(file_name.c_str(), O_RDONLY);if (fd_ == -1){size_ = 0;}else{struct stat st;int r = fstat(fd_, &st);if (r == -1){size_ = 0;close(fd_);}else{size_ = st.st_size;}} }void unmap_file() {if (fd_ != -1){close(fd_);munmap(buff_, size_);} } //if data is too big,create file spilt more file_index,mmap more times(hfrz ptr as start addr) int mmap_file(int fd, char *buff) {if (fd == -1){return -1;}buff = (char *)mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);if (buff == (void*)-1){std::ostringstream oslog;oslog << "mmap failed:" << strerror(errno);cout << oslog.str() << endl;close(fd);return -1;}return 0; }int main() {char *buff = (char *)malloc(1024);const char *str = "hello world";memcpy(buff, str, strlen(str)+1);printf("hello from ConsoleApplication1!\n");mmap_file(23, buff);getchar();return 0; }


然后選中調(diào)試,就彈出一個(gè)輸入遠(yuǎn)程主機(jī)的信息,這里就和xshell使用ssh協(xié)議連接信息一樣的輸入:


4.編譯調(diào)試,有個(gè)調(diào)試窗口要調(diào)出來,然后就可以看見linux控制臺(tái)的輸出信息了


編譯輸出控制臺(tái)



5.登陸遠(yuǎn)程主機(jī),可以看見啟動(dòng)的程序和源代碼了


6.簡(jiǎn)要的分析一下原理

從vs編譯的輸出控制臺(tái)我們可以看出編譯是使用mingw32交叉編譯,然后使用ssh協(xié)議將源代碼拷貝到目標(biāo)主機(jī),看見gdbserver進(jìn)程了,應(yīng)該是vs使用ssh協(xié)議作為client與遠(yuǎn)程主機(jī)的gdbserver調(diào)試


一些配置信息也說明了這一點(diǎn):


總結(jié)

以上是生活随笔為你收集整理的Visual Studio 2017开发linux程序使用实例及原理简析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。