简体   繁体   English

如何从 Windows 为 Linux (Dev-Cpp) 编译 C++ 代码

[英]How to compile C ++ code from Windows for Linux (Dev-Cpp)

我将 Dev-Cpp 程序与 MinGW 编译器一起使用,它允许您编译 C/C++ 代码以获得 Windows 启动器,但是是否有适用于 Windows 的编译器允许您为 Linux 创建可执行文件?

You can install Windows Subsystem for Linux, or set up a VM and do it that way.您可以安装适用于 Linux 的 Windows 子系统,或设置 VM 并以此方式进行操作。

Or as @user4581301 mentioned, use a cross-compiler.或者如@user4581301 所述,使用交叉编译器。

http://metamod-p.sourceforge.net/cross-compiling.on.windows.for.linux.html http://metamod-p.sourceforge.net/cross-compiling.on.windows.for.linux.html

Ignoring the fact that Dev-C++ has been obsolete for nearly a decade (I may have an unpopular opinion however that you should use whatever tools you can to learn whatever you can, even if that means using 'obsolete software' [as long as it's purely for learning and not production use])...忽略 Dev-C++ 已经过时近十年的事实(我可能有一个不受欢迎的意见,但是你应该使用任何你可以学习的工具来学习你可以学习的东西,即使这意味着使用“过时的软件”[只要它是纯粹用于学习而非生产用途])...

You have a couple options, one of which has been mentioned by somebody.您有几种选择,其中一个已被某人提及。 1.) Use a cross-compiler, and 2.) (which I personally would recommend, if it is viable for your particular needs) simply compile on actual Linux. 1.) 使用交叉编译器,和 2.)(我个人会推荐,如果它可以满足您的特定需求)只需在实际的 Linux 上编译。

To do this, you just need a working distribution of Linux with a development environment.为此,您只需要一个具有开发环境的 Linux 工作发行版。 You can use a virtual machine, Windows Subsystem for Linux (WSL), or a physical machine with Linux running on it.您可以使用虚拟机、适用于 Linux 的 Windows 子系统 (WSL) 或运行 Linux 的物理机。

From there, if you want the code to compile for multiple operating systems, you'll have to make sure your libraries and frameworks and other OS-specific code (eg, filesystem paths, system calls) are properly handled, or just use cross-platform libraries.从那里开始,如果您希望代码针对多个操作系统进行编译,则必须确保正确处理您的库和框架以及其他特定于操作系统的代码(例如,文件系统路径、系统调用),或者仅使用交叉平台库。 If you're dealing with standard C/C++, then this won't be of any concern.如果您正在处理标准 C/C++,那么这不会有任何问题。

Since Dev-C++ uses MinGW (the Windows port of GCC), then the actual compilation process should be the same, although on Linux IDEs are not commonly used, so you may have to get your hands dirty with shell commands, but that's not too hard once you get started.由于 Dev-C++ 使用的是 MinGW(GCC 的 Windows 端口),那么实际的编译过程应该是一样的,虽然在 Linux IDE 上并不常用,所以你可能不得不对 shell 命令动手,但这不是太一旦开始就很难。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++ new运算符返回新的意外-Dev-cpp - C++ new operator returning new unexpected -Dev-cpp wx dev-Cpp GDI加上问题 - wx dev-Cpp GDI plus problems Dev-Cpp“make.exe”错误代码= 0xc00000fd - Dev-Cpp “make.exe” error code = 0xc00000fd 差异dev-cpp和Microsoft Visual C ++ math.h - difference dev-cpp and Microsoft Visual C++ math.h 链表中的线性搜索[语言:C++ 编译器:Dev-Cpp 4.9.9.2] - Linear Search in Linked List [Language: C++ Compiler: Dev-Cpp 4.9.9.2] 如何在Linux发行版上将SFML C ++源代码从Linux编译到Windows? - How to Compile SFML C++ Source Code From Linux to Windows on a Linux Distro? 如何在 Linux / Windows 操作系统上显式使用文件 *.cpp 一步编译下面的代码? - How to compile the code below in one step using explicitly the files *.cpp on Linux / Windows operating system? fread()无法在Dev-Cpp中读取文件数据 - fread() fails to read file data in Dev-Cpp 如何在Linux中编译后以这样的方式编译c / cpp代码以提供经过预处理的汇编文件和目标文件? - how to compile c/cpp code in such a way that it gives preprocessed assembled and object file after compilation in linux? 如何在 Linux 中将 .cpp 文件编译为 Windows 可执行 (.exe) 文件 - How to compile a .cpp file into a Windows executable (.exe) file in Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM