将代码从 Linux 移植到 Windows [英] Porting code from Linux to Windows

查看:42
本文介绍了将代码从 Linux 移植到 Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Visual Studio .NET 2003,我正在尝试将我在 Linux GCC 中编写和编译/运行成功的代码移植到 Windows.

I'm using Visual Studio .NET 2003, and I'm trying to port code I've written and compiled/run successfully in Linux GCC to Windows.

我是使用 VS 的新手.我创建了一个新项目,并通过 Project -> Add Existing Items 将我拥有的所有 .c 和 .h 文件添加到项目中,然后选择了所有 .c 和 .h 文件.

I'm a newbie when using VS. I've created a new project, and added all the .c and .h files I have into the project by Project -> Add Existing Items, then chose all the .c and .h files.

我不熟悉编译器和链接器等的工作原理,但是 VS 和 gcc 编译/链接 #include 文件的方式有区别吗?我在 Linux 中编程的习惯是拥有一个 main.c 文件,并 #include 我需要的所有其他 .h 或 .c 文件.然后我只会编译 main.c 文件.但是在 VS 中,程序似乎没有看到"#include 文件,因为我收到错误,告诉我某些结构或变量没有声明,即使它们在我的用户定义的头文件中.

I'm not familiar with how exactly compilers and linkers etc work, but is there a difference between how VS and gcc compile/link #include files? My habit of programming in Linux has been to have one main.c file, and #include all other .h or .c files that I need. Then I would only compile the main.c file. But in VS, it seems as if the #include files are not "seen" by the program, because I'm getting errors that tell me certain structures or variables were not declared, even though they are in my user-defined header files.

我也收到错误,例如 DIR 是未声明的标识符.我已经包含了,为什么它不能识别 DIR?

I'm also getting errors like DIR is an undeclared identifier. I've included , so why can't it recognize DIR?

谢谢.

问候,雷恩

推荐答案

最好的学习方法之一是从您可以在两者上编译的最小应用程序开始.逐步将这个可工作且可移植的应用程序扩展为您想要的功能更齐全的应用程序.

One of the best ways to learn would be to start with the smallest application that you can compile on both. Expand this working and portable application step by step into the more fully featured application you desire.

记住将所有 .c/.cpp 文件添加到项目的源文件"目录中,否则它们不会被编译.

Remember to add all .c/.cpp files to the 'Source Files' directory in the project as they won't be compiled otherwise.

将任何不可移植的代码(您将需要的)限制在一个地方.例如,如果您需要创建线程,请在整个过程中使用一个通用的创建线程函数(但实现方式不同).使用 Boost 之类的可移植库在这方面会有所帮助.

Restrict any non-portable code (that you will need) to a single place. For example if you need to create threads, have a common create thread function used throughout (but implemented differently). Using portable libraries such as Boost can help here.

这篇关于将代码从 Linux 移植到 Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆