150

Linux で freeglut を使用して C++ (g++) でいくつかのエフェクトを作成し、次のようにコンパイルしました。

g++ -Wall -lglut part8.cpp -o part8

だから、必要なものすべてを含む静的にコンパイルされた Windows 実行可能ファイルを g++ で作成できるかどうか疑問に思っていましたか?

私は Windows を持っていないので、Linux でそれを行うことができれば、それは本当に素晴らしいことです :)

4

7 に答える 7

123

mingw32はLinux用のパッケージとして存在します。Windowsアプリケーションをクロスコンパイルしてリンクすることができます。ここCode::Blocksフォーラムにチュートリアルがあります。x86_64-w64-mingw32-gcc-win32たとえば、コマンドがに変わることに注意してください。

たとえば、UbuntuのリポジトリにはMinGWがあります。

$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]
于 2010-01-09T16:31:04.237 に答える
36

One option of compiling for Windows in Linux is via mingw. I found a very helpful tutorial here.

To install mingw32 on Debian based systems, run the following command:
sudo apt-get install mingw32

To compile your code, you can use something like:
i586-mingw32msvc-g++ -o myApp.exe myApp.cpp

You'll sometimes want to test the new Windows application directly in Linux. You can use wine for that, although you should always keep in mind that wine could have bugs. This means that you might not be sure that a bug is in wine, your program, or both, so only use wine for general testing.

To install wine, run:
sudo apt-get install wine

于 2013-07-19T07:30:59.873 に答える
18

パッケージ マネージャーから mingw64 などのクロス コンパイラをインストールします。次に、32 ビット Windows または64ビット Windows のgcccallを単に呼び出す代わりに、次の方法でコンパイルします。ターゲット システムにはすべてのライブラリが含まれていない可能性があるため、このオプションも使用します。i686-w64-mingw32-gccx86_64-w64-mingw32-gcc"--static

Fortran などの他の言語をコンパイルする場合は、前のコマンド-gccをに置き換えます。-gfortran

于 2016-01-13T19:01:58.940 に答える
7

Linuxでmingwを使用してCでWindows実行可能ファイルを作成しましたが、C++でも機能すると思います。

クロスコンパイラツールチェーンとしてclangやその他のものをパッケージ化するプロジェクトELLCCがあります。これを使用して、clang(C ++)、binutils、およびGDBforWindowsをコンパイルします。いくつかのLinuxホスト用にコンパイル済みのバイナリについては、 ellcc.orgのダウンロードリンクをたどってください。

于 2010-01-09T16:31:48.747 に答える
5

Fedora の場合:

# Fedora 18 or greater
sudo dnf group install "MinGW cross-compiler"

# Or (not recommended, because of its deprecation)
sudo yum groupinstall -y "MinGW cross-compiler"
于 2014-10-20T14:00:30.863 に答える
5

から: https://fedoraproject.org/wiki/MinGW/Tutorial

Fedora 17 では、win32 および win64 ターゲット用のバイナリを簡単にビルド (クロスコンパイル) できます。これは、mingw-w64 ツールチェーンを使用して実現されます: http://mingw-w64.sf.net/。このツールチェーンを使用すると、C、C++、Objective-C、Objective-C++、および Fortran のプログラミング言語のバイナリをビルドできます。

「Windows クロスコンパイラを使用するためのヒントとコツ」: https://fedoraproject.org/wiki/MinGW/Tips

于 2014-02-23T03:37:07.963 に答える