现在的位置: 首页 > 综合 > 正文

在window下编写linux代码

2013年08月29日 ⁄ 综合 ⁄ 共 2682字 ⁄ 字号 评论关闭

在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使用版后,毛病百出,最后以失败告终
只好“自己动手、丰衣足食”了,呵呵

 

    

 

抱歉!评论已关闭.