用vs2008编写和调试linux程序 ----VisualGDB 使用教程

来源:互联网 发布:南京未来软件南通 编辑:程序博客网 时间:2024/05/18 02:20

一准备工作

1 准备一台Linux机器用来编译程序,我用的是虚拟机安装的CentOS网络设置成桥接模式

     (1)安装并开启SSH

     (2)安装 gcc g++ gdb

     (3)关闭防火墙或者开启允许SSH对外访问的网络端口

2下载 VisualGDB 安装没什么好说的一路next就好了,然后打开vs2008会需要配置VisualGDB也是一路next就好了

二用vs2008建立一个的linux程序

1 新建工程,然后我们选择【VisualGDB】的【LinuxProject Wizard】

        

2 选择【Create a newproject】的【Application】

        

3 建立SSH 链接 选择【Build the projectunder Linux over network】


4选择【Remotecomputer】的 【create a new SSH】输入Linux电脑的ip地址以及用户名密码


5 接下去 next就好了 一个Linux工程就建好了

 

三创建和使用的静态库

1在刚刚的解决方案中新建工程


2 在新建项目时我们选择【Static library】


3 一路next,我就建好了一个静态库文件



4 引用静态库,修改上一个建立的工程


#include <iostream>#include "../Linux_static/Linux_static.h"using namespace std;int main(int argc, char *argv[]){char sz[] = "Hello, World!\n";//Hover mouse over "sz" while debugging to see its contentscout << "static library method :" << Linux_staticTest() << endl;cout << sz << endl;//<================= Put a breakpoint herereturn 0;}


5 建立依赖关系


6 编译 运行

 

四使用第三方的库 以boost库为例

1 在Linux上下载boost 并编译,将boost头文件拷贝到/usr/include 生成的so文件拷贝到/usr/lib 或者 /usr/lib64 (否则会编译能通过但是运行不了)

2  vs2008上新建工程 右键选择【VisualGDBProject Properties】


3 选择Makefile settings


Include directory 第三方库的头文件

Library directory 第三方库的库文件

Library directory 所需用库文件名字(注意:比如需要使用libboost_thread.so 时,只填boost_thread)



4 coding


#include <iostream>#include <boost/thread.hpp>using namespace std;void func(){cout << "this is a thread !" << endl;}int main(int argc, char *argv[]){boost::thread th1(func);th1.join();char sz[] = "Hello, World!\n";//Hover mouse over "sz" while debugging to see its contentscout << sz << endl;//<================= Put a breakpoint herereturn 0;}



0 0