使用 MS Visual studio 2010 构建的交叉编译应用程序

发布于 2024-10-09 17:42:33 字数 226 浏览 0 评论 0原文

我已经编写了一个代码,基本上适用于使用 VC++ 和开发环境 MS Visual Studio 2010 的 Windows。

注意:它是控制台应用程序,不包含 GUI。所以我想交叉编译。

我希望我的代码也能编译到 Linux,而不需要修改代码。我的意思是,我希望进行交叉编译。谁能简要介绍一下我的“操作方法”,或者将我重定向到 StackOverflow 上的一些帖子。

I have written a code, basically for windows using VC++ with development environment MS Visual Studio 2010.

Note: it is console- application and does not contain GUI. So I would like to cross- compile.

I want my code to compile to Linux as well without modifying the code. I mean, I Wish to do cross-compile. Can anyone please describe me briefly on "how-to" or re-direct me to few posts on StackOverflow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悟红尘 2024-10-16 17:42:33

虽然你可以,但我确信你可以找到一个针对 Linux 的 GCC 交叉编译版本,以便在 Windows 下运行(或者使用针对 Windows 平台的 GCC 版本从源代码构建它,例如 MINGW 或 cygwin),这可能会更容易在虚拟机中安装一个较小的 Linux 发行版,也许是一个只有控制台的发行版。

正如您所提到的,您已经使用 WIN32 API 完成了 I/O。您需要将其更改为 unix/posix 类型的方法,可能包括学习如何更改终端设置,这可能是一种学习体验。要知道您是否正确,您需要能够对其进行测试。在 cygwin 下构建代码的“linux”版本并在 Windows 机器上运行它可能可行,但最好熟悉实际的目标操作系统。

只需验证您的 Windows 可执行文件是否在 Dani 提到的 Wine 下运行也不是一个坏主意。还有一个库 Winelib,旨在通过在尝试为 Linux 编译代码时提供 Windows 调用的替代品来帮助移植。

最后,只要将编译器从 MSVC 切换到 GCC,无论您的目标是 Linux、Windows 还是 cygwin,都可能需要对源代码进行一些更改。 MSVC 会容忍许多 GCC 不会的危险行为,例如声明结构的方式。反之亦然。但是,通过一些学习并定期将项目提供给两个编译器,您可以维护可移植的代码。

While you can I'm sure dig up a linux-targeted version of GCC cross compiled to run under windows (or build it from sources using a version of GCC which targets the windows platform, such and MINGW's or cygwin's) it may prove easier to install a smaller linux distribution, perhaps a console-only one, in a virtual machine.

As you mentioned, you have done I/O using the WIN32 API. You will need to change this to unix/posix type methods, probably including learning about changing the terminal settings, which can be a bit of a learning experience. To know that you got this right, you'll need to be able to test it. Building the "linux" version of your code under cygwin and running it on your windows box might work, but it's probably best to gain some familiarity with the actual target operating system.

Just verifying that your windows executable runs under Wine which Dani mentioned wouldn't be a bad idea either. There's also a library, Winelib, that aims to help with porting by providing substitutes for the windows calls when trying to compile your code for linux.

Finally, just switching compilers from MSVC to GCC, regardless if you target linux or windows or cygwin, is probably going to require some changes to your source code. MSVC will tolerate a number of dodgy things that GCC won't, for example in how you declare structs. The reverse is probably also true. But with some learning and regularly feeding your project to both compilers, you can maintain portable code.

财迷小姐 2024-10-16 17:42:33

只要确保您使用 ANSI 版本的 c++(没有 clr 人员等),它也应该在 Linux 上编译。

您可能想要寻找一个将 csproj 转换为 makefile 的工具,或者自己编写它们。

Just make sure your using ANSI version of c++ (no clr staff ect.) and it should compile on linux as well.

you might want to look for a tool that converts csproj into makefiles, or write them yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文