visual studio 開發linux程序


VisualGDB支持Linux的原理是,通過ssh連接到Linux系統上通過ssh給linux下達命令 . (類似visualgdb的有windgb  ,這2個都是商業軟件。)

     Visual GDB把GDB調試工具集成到visual studio 開發環境中,在調試過程中,可以使用visual studio原有的單步執行、設定斷定等快捷鍵,還可以在visual GDB session的窗口中輸入GDB的調試命令,集成了visualGDB之后還可以在程序執行的過程中用鼠標懸停的方式查看和修改變量的值,這樣在不改變調試習慣的同時還可以使用GDB強大的調試功能,很不錯。

http://visualgdb.com/documentation/linux

 

官方的linux工具:

Visual C++ for Linux Development 

https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

https://visualstudiogallery.msdn.microsoft.com/725025cf-7067-45c2-8d01-1e0fd359ae6e

目標機要安裝gdb+gdbserver

 

 visualgdb教程:http://visualgdb.com/tutorials/linux/
 
我新建一個工程使用:
 
 
從上面可以看到就是把windows上面的文件通過scp copy到遠程主機上。
As the same source code will be edited under Windows and then compiled under Linux, VisualGDB will need to keep the sources synchronized. The easiest way is to use automatic file uploading via SSH. Alternatively, VisualGDB can setup shared folders (that would require root password).
 
他是怎么實現提示提示的,可以看到是通過下載linux下面的頭文件來實現的。會把linux下面的.h文件緩存到windows上面。
Press Finish to complete the wizard. If you are setting up your first project using this Linux machine, VisualGDB will make local caches of the include directories to make them available through IntelliSens 。
 
 
 
 
http://www.cnblogs.com/hbccdf/p/use_vs_and_visualgdb_develope_linux_app.html
 
 
 

使用Visual Studio 2017作為Linux C++開發工具

 

  https://www.cnblogs.com/dongc/p/6599461.html

https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

https://www.bilibili.com/video/av7718718/

ubuntu服務端安裝軟件:

sudo apt-get install openssh-server g++ gdb gdbserver

 

 

在第一次build之前會要求ssh連接到目標linux機器,填上用戶名密碼連接目標機器。如果需要更換目標機器地址,在Tools/Options/Cross Platform下進行管理。

 

 

設置好一系列選項(黑體部分),與普通的Win32程序的設置基本一致。需要注意如下2點:

 

  • vs不會自動把addtional include中的頭文件復制到本地來做代碼補全的提示,需要手動將linux下面的/usr/include目錄復制到vs的linux header path(如:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include\usr)
  • 注意,這一步一定要復制對,否則還會有找不到頭文件,沒有代碼提示等問題,是將linux下  /usr/include目錄整個復制到 ***\IDE\VC\Linux\include\usr下,如果還需要復制其他頭文件(/usr/local/include),照這個規則復制就可以,其實記住一點就可以:***\IDE\VC\Linux\include\usr這個目錄就相當於linux下/usr 目錄

 

 

vs2017默認的如上面,

我把ubuntu下面的/usr/ include include文件夾壓縮,然后把include里面的內容復制到上圖的include里面去 。一些unistd.h就可以找到了。

 (

Getting your include files

Everyone loves IntelliSense, but we’re not yet synchronizing the include files from your Linux system. Everyone has their own ways to either share or copy these files which is great. I wanted to share a really simple way to accomplish this I used in prepping the next section on the Intel Edison. I simply grab the whole folder locally onto my Windows box using PSCP. If you are on Windows 10 and have the Windows Subsystem for Linux installed you can do the exact same thing using scp.

pscp -r root@192.168.2.15:/usr/include .

Now on your project properties go to the VC++ Directories page and add your local path.

)

 

  • 提示,linux下使用gcc編譯的時候,加上-v參數,可以顯示所有搜索頭文件的路徑,保證目錄結構copy過來就可以

 

 

 

 vs還帶有自動copy linux頭文件到本地的功能:

菜單欄-》工具-》選項:

點更新會自動把linux下面的頭文件同步到windows上面來。下載下來的linux頭文件路徑在:C:\Users\ss\AppData\Local\Microsoft\Linux\HeaderCache

 (微軟的軟件一直很強大,很多都給你想好了)

 

 

 

https://www.zhihu.com/question/26388094

語法高亮,代碼補全

vs自身只帶了少部分的Linux頭文件,如果要用到其他頭文件或者第三方庫,可以將頭文件拷貝到本地目錄,然后將目錄添加到項目的include目錄中。

 

 

編譯時vs會將代碼復制到目標機器的~/projects/[project-name]目錄下,二進制文件在其目錄的bin目錄下。如下圖,Linux環境下可以看到,已經有代碼了。

 

打開 調試 -> ConsoleApplacation1屬性頁 就可以看到Visual C++ for Linux Development的各項配置。

 

 

 

  1. 比如在我的服務器上,調試模式生成的可執行文件的目錄是在~/projects/ConsoleApplication1/bin/x64/Debug

  2. 如果你有多台服務器的話,可以在 調試-> 選項 -> Cross Platform -> Connection Manager 處添加一台新的遠程服務器。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM