在Linux上针对Linux和Windows设置开发环境 [英] Set up a development environment on Linux targeting Linux and Windows

查看:126
本文介绍了在Linux上针对Linux和Windows设置开发环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于大学课程,我必须编写一个应该在Linux和Windows上都可以运行的http服务器. 我有一台不起眼的Linux机器,我认为它不能处理任何繁重的虚拟环境,我也不愿意经历安装它的麻烦.

For a university course I have to write a http server which is supposed to run on both Linux and Windows. I have got a humble Linux machine which I don't think can handle any kind of heavy virtual environment, neither I'm willing to go through the hassle of installing it.

这是我的第一个足够复杂的项目(我估计要开发约1.5个月),需要一个足够舒适的环境,以便在短编码和测试会议(当然是在两个平台上,后者)之间进行快速切换.

This is the first project of mine complex enough (I estimate ~1.5 months to develop) to require an environment sufficiently comfortable to alternate rapidly between short coding and testing sessions (the latter on both platforms, of course).

因此,我想知道对于这种情况最好的设置是什么.我认为在Wine上进行测试是可以的(毕竟这不是现实世界),我为Windows定位部分安装了MinGW.

So, I was wondering what could be the best set up for this situation. I think testing it on Wine would be ok (it is not a real-world thing, after all), and I installed MinGW for the Windows-targeting part.

基本上,一个简单的编写良好的makefile可以解决我的问题...它应该同时构建Linux和Windows二进制文件,并将它们放置在相应的文件夹中(Windows子目录位于Wine子树中),完毕!但是我对这件事没有经验,我真的不知道从哪里开始.也许是制作手册,啊!:)

Basically, a simple well-written makefile could solve my problem... It should build both the Linux and Windows binaries and place them in the respective folders (the Windows one in the Wine sub-tree) and I'm all done! But I feel very inexperienced in this thing and I really don't know where to start. Maybe the make manual, ahah!:)

想法,建议,任何我没想到/不知道的! 谢谢!

Thoughts, suggestions, anything I didn't think/know! Thank you!

(PS.我打算使用emacs作为编辑器,或者也许学习vim.除非eclipse提供某种类似于skynet的插件,才能完全解决此问题...:)

(PS. I'm planning to use emacs as editor, or maybe learn vim. Unless eclipse provide some kind of skynet-like plugin that entirely solve this problem...:)

推荐答案

您处在正确的轨道上.真的,这要归功于MinGW,它并不复杂.您基本上需要两件事:

You're on the right track. It's not that complicated, really, thanks to MinGW. You basically need two things:

  1. 该代码必须可跨操作系统移植. MinGW支持POSIX,但是您可能需要使用 Cygwin 才能使用POSIX接口或具有您自己的兼容性层,用于与OS进行接口.我可能会选择Cygwin,因为您只能针对POSIX进行编码,而不必测试和调试兼容性层.另外,请确保您不会使用任何特定于操作系统的外部库.不可移植的代码通常会导致编译错误,但是请确保无论如何都要对应用程序进行彻底的测试.

  1. The code has to be portable across the OSes. MinGW has some POSIX support, but you'll probably need to either use Cygwin in order to be able to use the POSIX interface or have your own compatibility layer for interfacing with the OS. I'd probably go for Cygwin as then you can code only against POSIX and won't have to test and debug your compatibility layer. Also, make sure you won't use any external libraries that are OS specific. Non-portable code often results in a compile error, but make sure you test the application thoroughly anyway.

针对Linux和Windows的工具链.您已经有了它们,您只需要正确使用它们即可.通常,在交叉编译期间调用工具链时,会使用诸如$(CROSS_COMPILE)之类的变量作为前缀.因此,在针对Linux进行编译时,您可以调用gcc,ld等(CROSS_COMPILE变量为空),而在针对Windows进行编译时,您可以调用例如. i486-mingw32-gcc,i486-mingw32-ld等,即CROSS_COMPILE = i486-mingw32-.或者只是根据目标定义CC,LD等.

The toolchains for targeting Linux and Windows. You already have them, you just need to use them correctly. Normally you'd use a variable like $(CROSS_COMPILE) as a prefix when calling the toolchain during cross compilation. So when compiling for Linux, you call gcc, ld, etc. (having the CROSS_COMPILE variable empty), and when compiling for Windows you call e.g. i486-mingw32-gcc, i486-mingw32-ld etc., i.e. CROSS_COMPILE=i486-mingw32-. Or just just define CC, LD etc. depending on the target.

我在Linux上编写了一个小游戏,并使其也可以在Windows上运行.如果您浏览代码,则可以看到该代码几乎没有#ifdef丛林(基本上只是一些额外的内容) Linux启用了调试功能),Makefile也很简单,没有复杂的交叉编译处理,只是有可能像应有的那样覆盖CC等.通过这种方式编写了许多重要的开源软件(尤其是台式机和嵌入式设备使用的软件),您还应该能够找到许多其他有关如何正确设置构建环境的示例.

I wrote a small game on Linux and made it run on Windows as well. If you browse the code, you can see the code has next to no #ifdef jungle (basically just some extra debugging features enabled for Linux), and the Makefile is simple as well, with no complicated handling for cross-compilation, just the possibility to override CC etc. like it should be. As lots of important open source software is written this way (especially software that's used by the desktop and embedded devices), you should also be able to find lots of other examples on how to set up the build environment correctly.

对于在Windows上测试应用程序,我认为最好的选择是如果您能以某种方式找到真正的Windows计算机.如果您正确执行所有操作,则该应用程序应与Linux上的运行方式相同,并且无需在两个OS上持续测试您的应用程序.如果无法在Windows机器上进行测试,则VM将是下一个最佳选择,尽管设置起来可能会更加困难. Wine是一个很好的备份计划,但是我认为如果仅在Wine上进行测试,就无法确定您的应用程序是否可以在Windows上正常运行.

As for testing the application on Windows, I think the best option is if you can find a real Windows machine somehow. If you do everything correctly, it should run the same as on Linux and you won't need to continuously test your application on both OSes. If testing on a Windows machine is not possible, a VM would be the next best choice, though it would probably be more difficult to set it up. Wine is a good backup plan, but I don't think you can be sure your application works well on Windows if you only tested it on Wine.

这篇关于在Linux上针对Linux和Windows设置开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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