Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > 在window下编写linux代码
【标  题】:在window下编写linux代码
【关键字】:window,linux
【来  源】:http://blog.csdn.net/laomai/archive/2006/10/30/1357114.aspx

在window下编写linux代码

Your Ad Here

在windows环境下写linux代码
我在linux下写代码时一直找不到方便的工具,vi和emacs虽然提供了自动完成的功能,但是还是没有
vc+visual assistant方便,因此就产生了在windows下 linux代码的想法,这个企图曾经被狒狒鄙视为
“自做孽,不可活”,不过经过实践,村长我还是活过来了:-)
一、实验环境
1、装有win2k的机器一台,并装好了vc6+vs2003+visual assistant+source insight
2、装有linux as3的机器一台,安装了所有的软件包
二、步骤
1、将linux机器上的/usr/include拷贝到windows机器上的指定目录如
f:/linuxhead下
把/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include/也拷到刚才的目录下,该个名字为"gcchead"
2、在vs2003的头文件包含路径("工具"->"选项"->“项目”->"vc++目录"->"包含文件")加入刚才的
f:/linuxhead/include目录
f:/linuxhead/gcchead/include目录
并保证这两个目录在目录列表的最上方
3、建立一个空项目,加入一个 main.cpp文件,然后将常用的linux头文件包含进去,编译之。
//main.cpp的内容
#include <sys/types.h>
#include <sys/socket.h> 
#include <time.h> 
#include <sys/time.h>
#include <netinet/in.h> 
#include <arpa/inet.h> 
#include <errno.h>
#include <fcntl.h>  
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h> 
#include <sys/uio.h>  
#include <unistd.h>
#include <sys/wait.h>
#include <sys/un.h>  
#include <sys/select.h> 
#include <sys/param.h> 
#include <sys/poll.h>
#include <strings.h>  
#include <sys/ioctl.h>
#include <pthread.h>
#include <syslog.h>
#include <termios.h>
#include <grp.h>
#include <pwd.h>
#include <sys/resource.h>
#include <setjmp.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <linux/dirent.h>
#include <linux/unistd.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/utsname.h>
#include <utime.h>
#include <sys/wait.h>
int main(int argc ,char* argv[])
{
  return 0;
}

编译时出现的错误依次为
1、bits\types.h(31): fatal error C1083: 无法打开包含文件:“stddef.h”: No such file or directory
说明没找到stddef.h文件
发现/linux目录下有这个文件,将linux目录加到包含目录里

2、bits\in.h(69): error C2380: “ip_opts”前的类型(构造函数有返回类型或是当前类型名称的非法重定义?)
因为
struct ip_opts
  {
    struct in_addr ip_dst; /* First hop; zero without source route.  */
    char ip_opts[40];  /* Actually variable in size.  */
  };成员名与结构名相同,vc认为是错误,所以只好改成员名为ip_opta
 
3、gcchead\include\stdarg.h(43): error C2146: 语法错误 : 缺少“;”(在标识符“__gnuc_va_list”的前面)
typedef __builtin_va_list __gnuc_va_list;
由于__builtin_va_list类型不存在,所以改为
typedef void*  __gnuc_va_list;

4、stdlib.h(833): error C2065: “wchar_t” : 未声明的标识符
extern int mbtowc (wchar_t *__restrict __pwc,
     __const char *__restrict __s, size_t __n) __THROW;
在前面增加一句
#include "linux/Nls.h"

5、linux\nls.h(7): error C2146: 语法错误 : 缺少“;”(在标识符“wchar_t”的前面)
typedef __u16 wchar_t;
增加
#include "asm/types.h"

6、asm\types.h(11): error C2144: 语法错误 : “char”的前面应有“;”
typedef __signed__ char __s8;
增加一句#define __signed__ signed

7、linux\dirent.h(6): error C2146: 语法错误 : 缺少“;”(在标识符“d_off”的前面)
__kernel_off_t d_off;
增加一行#include "asm/posix_types.h"

8、linux\dirent.h(12): error C2146: 语法错误 : 缺少“;”(在标识符“d_ino”的前面)
 __u64  d_ino;
 增加一行#include "asm/types.h"
 并在asm/types.h文件里增加两行
typedef __signed__ long long __s64;
typedef unsigned long long __u64;


解决上述问题后,编译通过.

p.s网友超越无限曾告诉我magic c++也能实现我需要的功能,然而我下载了他的4.0使用版后,毛病百出,最后以失败告终
只好“自己动手、丰衣足食”了,呵呵

 

    


 

对后缀自增自减的误解:【上一篇】
C语言编程,从菜鸟到高手:【下一篇】
【相关文章】
  • Linux C++程序运行的问题
  • 1.忘记window.onload吧 - JQuery 15天(翻译+学习总结)
  • Linux下使用CUPS提供打印服务
  • 教教你用Linux 防火墙保护你的ADSL连接
  • Others——Linux系统备份及恢复
  • 对 Linux 内核进行压力测试
  • 让UNIX和Linux一起工作
  • Reinstall amule on linux
  • 甲骨文宣布支持Linux的业务
  • 甲骨文为什么Linux?
  • 【随机文章】
  • 严重: Error listenerStart的解决办法
  • 布线系统 接地
  • Win32教程29-Win32调试API 第二部分
  • 嵌人式实时操作系统uC/OS在控制工程中的应用
  • 如何设置一个基本的OpenLDAP Server
  • PPP:点对点协议
  • 什么是“双机系统”?
  • Sybase PowerBuilder9.0 高速开放式集成开发环境
  • 两种方法测试数据文件的移动
  • 怎樣在查詢結果中加入子序號 ?
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.