トップページ > 記事閲覧
MinGWでリンクできない
名前:しゅう 日時: 2017/08/15 19:32

初投稿です MinGWで実行ファイルを作りたいのですが、過去の質問を参考にしてもリンクができません コンパイルはできます(エラーにはなりません) test.cppはフォルダ5_3_0_i686を入れているフォルダに入れてあります test.cppの内容はhtp://dxlib.o.oo7.jp/use/dxuse_gcc.htmlのものです 環境 OS:Windows10 gcc:ver5.3.0 g++ -c -I.\5_3_0_i686 -DDX_GCC_COMPILE -DDX_NON_INLINE_ASM test.cpp g++ -L.\5_3_0_i686 -Wl,"--no-as-needed" -mwindows -lDxLib -lDxUseCLib -lDxDrawFunc -ljpeg -lpng -lzlib -ltiff -ltheora_static -lvorbis_static -lvorbisfile_static -logg_static -lbulletcollision -lbulletmath -lopusfile -lopus -lsilk_common -lcelt test.o test.o:test.cpp:(.text+0x7): undefined reference to `DxLib::DxLib_Init()' test.o:test.cpp:(.text+0x34): undefined reference to `DxLib::GetColor(int, int, int)' test.o:test.cpp:(.text+0x4c): undefined reference to `DxLib::DrawPixel(int, int, unsigned int)' test.o:test.cpp:(.text+0x51): undefined reference to `DxLib::WaitKey()' test.o:test.cpp:(.text+0x56): undefined reference to `DxLib::DxLib_End()' collect2.exe: error: ld returned 1 exit status 当方プログラミング初心者なのでとても初歩的なミスがあるかもしれません それと、-Wl,"--no-as-needed"と-mwindowsというオプションは他の方が使っているようなのでつけたのですが、 何の意味があるのかよくわかりません これも教えてもらえると幸いです
メンテ

Page: 1 |

Re: MinGWでリンクできない ( No.1 )
名前:管理人 日時:2017/08/16 00:41

私が手元で 5.3.0 i686 のバージョンで実行ファイルを作成した際のコマンドは以下のような感じでした <Sample.cpp をコンパイルしてSample_5_3_0_i686.exe を作成する batファイルの記述> g++.exe -c Sample.cpp -o Sample.o -DDX_GCC_COMPILE -DDX_GCC_COMPILE_5_3_0 -DDX_NON_INLINE_ASM --input-charset=cp932 --exec-charset=cp932 -I"D:\MinGW_5_3_0_i686\include" -I"D:\MinGW_5_3_0_i686\lib\gcc\mingw32\5.3.0\include" -I"D:\MinGW_5_3_0_i686\lib\gcc\mingw32\5.3.0" -I"D:\DxLib_GCC\プロジェクトに追加すべきファイル_GCC(MinGW)用\5_3_0_i686" g++.exe Sample.o -o "Sample_5_3_0_i686.exe" -L"D:\DxLib_GCC\プロジェクトに追加すべきファイル_GCC(MinGW)用\5_3_0_i686" -L"D:\MinGW_5_3_0_i686\lib" -L"D:\MinGW_5_3_0_i686\lib\gcc\mingw32\5.3.0" -mwindows -luser32 -lgcc -lDxLib -lDxUseCLib -lDxDrawFunc -ljpeg -lpng -lzlib -ltiff -ltheora_static -lvorbis_static -lvorbisfile_static -logg_static -lbulletdynamics -lbulletcollision -lbulletmath -lopusfile -lopus -lsilk_common -lcelt ( 上記の『D:\MinGW_5_3_0_i686』と『D:\DxLib_GCC\プロジェクトに追加すべきファイル_GCC(MinGW)用\5_3_0_i686』と 記述されている箇所はお手元の MinGW 5.3.0 i686 版のフォルダとDXライブラリ MinGW 5.3.0 i686 用のフォルダの パスに置き換えてください ) そして最新バージョンでは手元でも『GUID_NULL が見つからない』というリンクエラーが 発生してしまっていたので、それを修正したバージョンをアップしました お手数で申し訳ありませんが、よろしければこちらの修正バージョンをお使いください m(_ _;m https://dxlib.xsrv.jp/temp/DxLibGCC_MinGWTest.exe // Windows版 MinGW 用 こちらを使用して、且つ上記のコマンドを使ってもエラーが発生してしまう場合は しゅうさんがお使いの 5.3.0 と、DXライブラリ MinGW 5.3.0 i686 版をビルドした際の 5.3.0 が異なるものである可能性があります( Gnu 系はバージョンが同じでもビルドの設定が 少しでも異なるとライブラリファイル( aファイル )の流用ができないことが多い為 ) なので、その場合はしゅうさんがお使いの 5.3.0 が配布されているウェブサイトのURLを教えてください m(_ _;m > それと、-Wl,"--no-as-needed"と-mwindowsというオプションは他の方が使っているようなのでつけたのですが、 > 何の意味があるのかよくわかりません 『--no-as-needed』は私の場合は使用していないのであまりわかりませんが、どうやらデフォルトの動作の 『--as-needed』は『使われていないコードはリンクしない』といった無駄を省いてくれる動作をするようなのですが、 これが上手く動作せずリンクエラーになったりすることがあるので『--no-as-needed』を追加して 『--as-needed』を無効化しているようです 『-mwindows』は WinMain から始まる Win32アプリのプログラムをリンクする際に記述するもののようです main 関数から始まるコンソールアプリでは必要ないオプションだと思います
メンテ
Re: MinGWでリンクできない ( No.2 )
名前:しゅう 日時:2017/08/16 18:01

回答ありがとうございます MinGWのhファイルなどへの参照がされていなかったようです 参照させたところ、 .\5_3_0_i686/libDxLib.a(DxMovieWin.o):DxMovieWin.cpp:(.text+0x238f): undefined reference to `GUID_NULL' 以下多くのエラーを返してきました そこでその修正バージョンの.exeファイルを使ったのですが、これは実行させるだけでよいものでしょうか? 実行させた後でコマンドプロンプトを再起動させてコンパイル&リンクしようとしましたが、上のエラーと同じエラーが返ってきました 自分のパソコンにあるMinGWのダウンロード元ですが、自分の力では調べることができませんでした gcc -v の情報を載せれば解決するものでしょうか? それと、-mwindowsオプションについてですが、DXライブラリで作るものはウィンドウアプリに含まれるものですか?
メンテ
Re: MinGWでリンクできない ( No.3 )
名前:管理人 日時:2017/08/17 01:10

> .\5_3_0_i686/libDxLib.a(DxMovieWin.o):DxMovieWin.cpp:(.text+0x238f): undefined reference to `GUID_NULL' > 以下多くのエラーを返してきました よろしければ10個ほどエラーの内容を教えていただけないでしょうか? ( 最初のお書き込みのようなエラーでしょうか? ) > そこでその修正バージョンの.exeファイルを使ったのですが、これは実行させるだけでよいものでしょうか? > 実行させた後でコマンドプロンプトを再起動させてコンパイル&リンクしようとしましたが、上のエラーと同じエラーが返ってきました すみません説明不足でした DxLibGCC_MinGWTest.exe は圧縮ファイルの自己解凍形式のもので、実行すると DxLibGCC_MinGWTest.exe があるフォルダに DxLibGCC_MinGWTest というフォルダが作成されますので、その中にある 5_3_0_i686 フォルダを 既存の プロジェクトに追加すべきファイル_GCC(MinGW)用\5_3_0_i686 に上書きしてください m(_ _)m > 自分のパソコンにあるMinGWのダウンロード元ですが、自分の力では調べることができませんでした > gcc -v の情報を載せれば解決するものでしょうか? うーんどうでしょう、分からないかもしれませんが、よろしければ gcc -v の内容を掲示板にそのまま 書き込んでください m(_ _)m お使いの MinGW はお使いのPCに最初からインストールされていたのでしょうか? > それと、-mwindowsオプションについてですが、DXライブラリで作るものはウィンドウアプリに含まれるものですか? はい、DXライブラリを使用して作成されるアプリはウインドウアプリです
メンテ
Re: MinGWでリンクできない ( No.4 )
名前:しゅう 日時:2017/08/17 19:52

古い5_3_0_i686ファイルを新しい5_3_0_i686ファイルに置き換えたところ、以下のエラーが返されました これは、古い5_3_0_i686ファイルを使用した時のエラーからGUID_NULLに関するエラーをなくしたものと一致します 何か操作を間違えているのでしょうか... .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x778): undefined reference to `D_btRigidBody::setCenterOfMassTransform(D_btTransform const&)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0xecc): undefined reference to `D_btGeneric6DofSpringConstraint::D_btGeneric6DofSpringConstraint(D_btRigidBody&, D_btRigidBody&, D_btTransform const&, D_btTransform const&, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x1049): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x1062): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x107c): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x1095): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x10af): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x10c8): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x10d3): undefined reference to `D_btGeneric6DofConstraint::calculateTransforms()' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x10db): undefined reference to `D_btGeneric6DofSpringConstraint::setEquilibriumPoint()' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x1163): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x117c): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x11a3): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x11bc): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x11e3): undefined reference to `D_btGeneric6DofSpringConstraint::enableSpring(int, bool)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x11fc): undefined reference to `D_btGeneric6DofSpringConstraint::setStiffness(int, float)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x184e): undefined reference to `D_btRigidBody::D_btRigidBody(D_btRigidBody::D_btRigidBodyConstructionInfo const&)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x3c49): undefined reference to `D_btSequentialImpulseConstraintSolver::D_btSequentialImpulseConstraintSolver()' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x3c7b): undefined reference to `D_btDiscreteDynamicsWorld::D_btDiscreteDynamicsWorld(D_btDispatcher*, D_btBroadphaseInterface*, D_btConstraintSolver*, D_btCollisionConfiguration*)' .\5_3_0_i686/libDxUseCLib.a(DxUseCLibPhysics.o):DxUseCLibPhysics.cpp:(.text+0x3ca4): undefined reference to `D_btDiscreteDynamicsWorld::setGravity(D_btVector3 const&)' collect2.exe: error: ld returned 1 exit status gcc -v の返答は以下の通りです(見やすくするために改行を入れました) Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe Target: mingw32 Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls : (reconfigured) ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls Thread model: win32 gcc version 5.3.0 (GCC)
メンテ
Re: MinGWでリンクできない ( No.5 )
名前:管理人 日時:2017/08/18 01:53

gcc -v の内容を載せていただきありがとうございます 私の手元の 5.3.0 の gcc -v は以下のようになっていて、Thread model が posix であったりなど、それなりに異なる点があります Using built-in specs. COLLECT_GCC=gcc Target: mingw32 Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads=posix --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls Thread model: posix gcc version 5.3.0 (GCC) ただ、載せていただいた情報からしゅうさんと同じ環境を再現できるかもしれないので、 次の週末に試してみたいと思います 申し訳ありませんが数日ほどお待ちください m(_ _;m
メンテ
Re: MinGWでリンクできない ( No.6 )
名前:管理人 日時:2017/08/19 20:38

すみません、幾つか配布されている MinGW のパッケージを試してみたのですが しゅうさんが載せていただいた構成のものはありませんでした 申し訳ありませんがしゅうさんの方でインストール元のパッケージをダウンロードされた ウェブサイトがわからないとなると、対応するのは難しそうです… 逆にしゅうさんの方で使用される MinGW のバージョンの変更が許されるのでしたら 例えばこちら <MinGW - Minimalist GNU for Windows> https://sourceforge.net/projects/mingw/files/ の「Download mingw-get-setup.exe (86.5 kB)」からダウンロードできるインストーラーで インストールできる 6.3.0 用のDXライブラリのライブラリファイルを作成するといった ことができるのですが、お使いの MinGW のバージョンを変更するのは難しいでしょうか?
メンテ

Page: 1 |

題名
名前
コメント
パスワード (記事メンテ時に使用)

   クッキー保存