分享

how to build and debug Linux ap

 迎风初开 2013-12-03

Using Visual Studio to develop Linux apps

This tutorial demonstrates how to build and debug Linux applications using Visual Studio.

To proceed with the tutorial you will need a Windows machine and a Linux machine. You can use 2 physical computers, a Windows computer running Linux inside VirtualBox/VMWare or vice versa.

To create, build and debug a simple Linux app using VisualGDB, please follow these steps:

  1. Please download and install the latest VisualGDB.
  2. On your Windows machine start Visual Studio, select "File->New project". Then select "VisualGDB->Linux Project Wizard". Specify project location and press "OK".http:///tutorials/linux/img/01-newproj.png
  3. The VisualGDB Linux Project Wizard will start. As we are making a simple "Hello, World" application, keep "Create a new project" selected and press "Next". http:///tutorials/linux/img/02-newapp.png
  4. If you have not created any projects before, select "Create a new SSH connection" on the next page.http:///tutorials/linux/img/03-newssh.png
  5. Provide the host name, user name and password. It is recommended to check the "setup public key" checkbox, so that VisualGDB will automatically generate an public/private keypair, store it in your Windows account's key container and setup the remote Linux machine to use it. http:///tutorials/linux/img/04-sshconn.pngIf you don't enable public key authentication, VisualGDB will remember your password for this connection. The stored passwords are encrypted using a key stored in your Windows account. Thus, the password will only be available once you login using your Windows account.
  6. If you want to use a different toolchain (e.g. LLVM), you can select if from the toolchain list. The button to the right of the toolchain list allows customizing individual tools, such as the compiler. http:///tutorials/linux/img/05-connsel.pngYou can also select a cross-compiler here or specify a different deployment machine. Use the diagram at the bottom of the page to check the correctness of your setup:
    •  The hammer icon corresponds to the machine where the compiler is run.
    • The "play" icon corresponds to the machine where the debugged program is launched.
  7. When you press "Next", VisualGDB will test your toolchain by trying to compile and run a trivial program. If any errors are detected at this stage, you will see a detailed error log with further troubleshooting information. http:///tutorials/linux/img/06-verify.png
  8. 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).http:///tutorials/linux/img/07-transfer.png
  9. 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 IntelliSense.http:///tutorials/linux/img/08-includecache.png
  10. Congratulations! The project has been created. You can now build your project, set a breakpoint on the "cout" line and start debugging with F5.http:///tutorials/linux/img/09-breakpoint.png
  11. You can always change various debugging settings by right-clicking at the project in Solution Explorer and selecting "VisualGDB Project Properties". The properties window allows changing various settings and also copying settings between configurations. Use the search field on the left to find settings by keywords:http:///tutorials/linux/img/10-projectprops.png
  12. VisualGDB uses GNU make to build your project. You can easily customize various GCC settings, such as additional include directories or compiler flags, by editing the flags.mak file:http:///tutorials/linux/img/11-make.pngNote that IntelliSense include directories are managed separately from the VisualGDB Project Properties window. If you are adding a custom include directory, please add it to both flags.mak and the IntelliSense property page.
  13. You can also right-click inside Visual Studio menu bar and enable the VisualGDB toolbar. It provides shortcuts to commonly used functionality (e.g. changing the program arguments for next launch): http:///tutorials/linux/img/12-toolbar.png
  14. Note that when you add further source files to the project, the Makefile will be updated automatically next time you build the project in Visual Studio.

 

That was it for the basic project. If you want a more advanced example, see our

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多