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

48 篇文章 0 订阅

来自:

http://blog.csdn.net/flb_1990/article/details/20699099

一准备工作

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 引用静态库,修改上一个建立的工程


[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include <iostream>  
  2. #include "../Linux_static/Linux_static.h"  
  3. using namespace std;  
  4.   
  5. int main(int argc, char *argv[])  
  6. {  
  7.     char sz[] = "Hello, World!\n";  //Hover mouse over "sz" while debugging to see its contents  
  8.     cout << "static library method :" << Linux_staticTest() << endl;  
  9.     cout << sz << endl; //<================= Put a breakpoint here  
  10.     return 0;  
  11. }  


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


[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include <iostream>  
  2. #include <boost/thread.hpp>  
  3. using namespace std;  
  4.   
  5.   
  6. void func(){  
  7.     cout << "this is a thread !" << endl;  
  8. }  
  9.   
  10. int main(int argc, char *argv[])  
  11. {  
  12.     boost::thread th1(func);  
  13.     th1.join();  
  14.     char sz[] = "Hello, World!\n";  //Hover mouse over "sz" while debugging to see its contents  
  15.     cout << sz << endl; //<================= Put a breakpoint here  
  16.     return 0;  
  17. }  


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值