移植win32代码(windows.h)到linux [英] porting win32 code (windows.h) to linux

查看:193
本文介绍了移植win32代码(windows.h)到linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个c ++项目,我有一堆Visual Studio生成的项目文件,我想移植到linux。我本质上是在Windows上的多个文件中使用windows.h头文件。现在,我不确定,因为明确存在没有linux.h文件(incase它,请指导我在哪里看)。在Linux上我使用Eclipse CDT进行开发。我有两个想法,它可能会在linux上工作,但我想让你的输入知道什么正确的方向:



(1)删除窗口在C ++文件中使用Linux API调用的API调用。但这意味着,我必须在linux中找到等效的函数,我不知道在哪里看。例如。 Filetime在Win32相当于在linux的东西(还没有找到这个东西)。



(2)我复制这些函数的基本语法.h),只是创建一个头文件(让我说它命名为linux.h),并将这个头文件包含在linux的项目中。



发现我很困惑如何将事情向前推进。我只想工作这个东西。请建议我以下的想法/意见:
(1)不,我不想使用Boost。
(2)我不想在Visual Studio中重写文件。

解决方案

应用。如果它的一个非gui app命令行。你应该看看用兼容不同平台(linux,Mac OS X)的posix版本的函数替换你的win32调用。



这是选项1.您可以将Filetime转换为posix 此处< a>,并用你自己的函数包装它,每个你想要编译的os都有一个#ifdef。



选项2是一个痛苦,但它仍然可以是一个选项,它真的取决于你在源代码中有多少Win32函数,以及它们与posix版本有多么不同。我不推荐这个选项。



选项1是更好的一旦你学习了posix版本的win32函数,只是停止使用win32函数尽可能。 p>

I'm working on a c++ project where I have bunch of Visual Studio generated project files that I want to port to linux. I essentially am using windows.h header file in multiple files on Windows. Now, I'm unsure as there explicitly exists no linux.h file (incase it does, please guide me where to look at). On linux I'm using Eclipse CDT for development. I've two ideas in mind of how possibly it would work on linux but I want your input to know what the right direction is:

(1) To remove the windows API calls with Linux API calls in the C++ files. But this would mean, I've to find equivalent function in linux which I am not sure where to look at. eg. Filetime in Win32 is equivalent to something in linux (haven't found this thing yet).

(2) I copy the basic syntax of these functions (as written in windows.h) and just create a header file (lets say i name it linux.h) and include this header file in project on linux.

So, apparently you might have figured out that I'm confused of how to move things ahead. I just want to work this thing out. Please suggest me ideas/views other than following: (1) No, I don't want to use Boost. (2) I don't want to rewrite the files in Visual Studio.

解决方案

It really depends on your application. If its a non-gui app command line only. You should look at replacing your win32 calls with posix versions of the functions which are compatible with different platforms (linux, Mac OS X).

So that is option 1. You can convert Filetime to posix here and wrap it with your own function that has an #ifdef for each os you want to compile on.

Options 2 is a pain, been there done that. But it can still be an option, it really depends on how many Win32 functions you have in your source code and how different they are from the posix version. I do not recommend this option.

Option 1 is better once you learn the posix versions of the win32 functions and just stop using the win32 function as much as possible.

这篇关于移植win32代码(windows.h)到linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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