• 締切済み

MinGW-gccでの実行ファイル作成法

今まで、visual studio 2008を使用して、実行ファイルを作っていたのですが、 今回、gccで実行ファイルを作らなければいけなくなりました。 どなたかどういったコマンドオプションを用いれば実行ファイル作成までたどりつくのか 知っている方がいれば教えていただきたいです。 ちなみに、現在 >g++ -o p -O3 -lm ./src/p.cpp ./src/m.cpp -L ./ -lica とコマンドを打っていますが : undefined reference to `_imp___Z13icaPdiiS_b'  とリンクが上手くいっていない感じのエラーが返ってきます。 このエラーの改善方法についてもぜひどなたかご教授ください。 お願いします。

みんなの回答

  • D-Matsu
  • ベストアンサー率45% (1080/2394)
回答No.1

もっとも単純には、 g++ (ソースファイル) だけで出来上がります。もちろん最適化やインクルードパス、参照ライブラリなどの設定が必要ならその辺りのオプション記述は必要ですが。 ぱっと見た感じではコマンドラインには問題なさそうです。出力ファイル名のpはどうかと思いますが。 undefined referenceは要するに「参照されているにも関わらず、実体定義がないシンボルがある」ということです。

関連するQ&A

  • Windowsコモンコントロールのcygwin/gccコンパイルエラー

    以下のサイトのようなWindowsコモンコントロールのプログラムをcygwin/gccコンパイルするとエラーがでます。 (sourceのサイト) http://wisdom.sakura.ne.jp/system/winapi/common/common16.html (ビルドコマンド) gcc -mwindows -mno-cygwin -o main.exe main.cpp (エラー出力) undefined reference to `_ImageList_Destroy@4' undefined reference to `_InitCommonControls@0' undefined reference to `_ImageList_Create@20' undefined reference to `_ImageList_ReplaceIcon@12' undefined reference to `_ImageList_ReplaceIcon@12' collect2: ld returned 1 exit status make: *** [main.exe] Error 1 Windowsコモンコントロールを含んだプログラムをcygwin/gccコンパイルするにはどうすればよいでしょうか? コンパイルは出来ないのでしょうか? よろしくお願いします。

  • MingwでC++のソースがコンパイルできない。

    質問があるのですがよろしくお願いしします。 プラットフォームは Windows HOME です。 MinGWでC++のhelloworld.cppという名前のプログラム ------ここから----------- #include <iostream> using namespace std; int main(){ cout <<"Hello World!!\n"; return 0; } -------ここまで----------- を、gcc helloworld.cpp とWindowsのコマンドプロンプトから打ってコンパイルしようとしたのですが、 undefined reference to std string::size() const undefined reference to std string::operator[](using int) const undefinrd reference to std::cout undefinrd reference to std::basic_ostream<char, std::char traits<char> >&, char const*) undefinrd reference to std::ios_base::Init::() undefinrd reference to std::ios_base::~Init::() などのエラーが出て、コンパイルできません・・ hello.cという名前のC言語プログラム --------ここから------ #include<stdio.h> int main(void){ printf("Hello GCC World on Windows!!\n"); } ------ここまで------- は、gcc hello.c で正常にコンパイルでき、生成したexeファイルも正常に動きます。 また、eclipse CDT上からc++プログラムをMinGWでコンパイルすることもできるのですが・・ なぜかWindowsのコマンドプロンプトからc++プログラムをコンパイルしようとするとエラーが出てしまいます。(C言語のプログラムでもエラーが出ることが時々あります。) どなたか詳しい方いらっしゃいましたらご教授頂けると幸いです。 よろしくお願いします。

  • エラーが改善できません。

    C:\__Home\Visual Studio 2008\Projects\fecgsepfast>make MAKE Version 5.2 Copyright (c) 1987, 2000 Borland g++ -o fecgsep -O3 -lm ./src/fecgsep.cpp ./src/mem_util.cpp -L ./ -lica_ dll_amd ./src/fecgsep.cpp: In function 'int main(int, char**)': ./src/fecgsep.cpp:245:22: warning: name lookup of 'i' changed ./src/fecgsep.cpp:28:9: warning: matches this 'i' under ISO standard rules ./src/fecgsep.cpp:203:17: warning: matches this 'i' under old rules C:\DOCUME~1\Wada\LOCALS~1\Temp\cc6RcquX.o:fecgsep.cpp:(.text+0x41f): undefined r eference to `_imp___Z13fnica_dll_amdPdiiS_b' C:\DOCUME~1\Wada\LOCALS~1\Temp\cc6RcquX.o:fecgsep.cpp:(.text+0x718): undefined r eference to `_imp___Z13fnica_dll_amdPdiiS_b' collect2: ld returned 1 exit status ** error 1 ** deleting a.out というエラーが改善できません。どなたかアドバイスをお願いします。

  • Cppunitのビルドエラー解消

    お世話になります。 Cppunitでテストケースを作成し、ビルドしようとしておりますが、ビルドをすることができません。 ・以下がエラーログの抜粋ですが、「TestRunnerClient.o:TestRunnerClient.cpp:~」の行がEclipse上で赤く表示されており、原因だと思われます。基本的な質問で恐縮ですが、エラーの解消方法をご存知の方がおられればご教示頂けると助かります。 ・プロジェクトのライブラリ指定は添付の画像のようにしております。この部分の指定に誤りはございませんでしょうか。 d000000.o:(.idata$2+0x0): multiple definition of `_head_libcppunit_1_12_1_dll' C:\MinGW\msys\1.0\cppunit-1.12.1\src\cppunit\.libs/libcppunit.dll.a(d000387.o):(.idata$2+0x0): first defined here d000001.o:(.idata$5+0x0): multiple definition of `_imp___ZTVN7CppUnit27TestSuiteBuilderContextBaseE' C:\MinGW\msys\1.0\cppunit-1.12.1\src\cppunit\.libs/libcppunit.dll.a(d001116.o):(.idata$5+0x0): first defined here d000001.o:(.idata$6+0x0): multiple definition of `_nm___ZTVN7CppUnit27TestSuiteBuilderContextBaseE' C:\MinGW\msys\1.0\cppunit-1.12.1\src\cppunit\.libs/libcppunit.dll.a(d001116.o):(.idata$6+0x0): first defined here d000002.o:(.idata$7+0x0): multiple definition of `libcppunit_1_12_1_dll_iname' C:\MinGW\msys\1.0\cppunit-1.12.1\src\cppunit\.libs/libcppunit.dll.a(d001147.o):(.idata$7+0x0): first defined here TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x34f): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x375): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x54f): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x575): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x99d): undefined reference to `gethostname@8' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x9e8): undefined reference to `gethostname@8' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xa4b): undefined reference to `WSAStartup@8' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xa7f): undefined reference to `socket@12' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xa9b): undefined reference to `gethostbyname@4' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xae8): undefined reference to `htons@4' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xb3b): undefined reference to `connect@12' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0xbac): undefined reference to `select@20' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x121e): undefined reference to `closesocket@4' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x1226): undefined reference to `WSACleanup@0' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x138e): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x13b4): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x23ff): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x2425): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x358f): undefined reference to `send@16' TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x35b5): more undefined references to `send@16' follow TestRunnerClient.o:TestRunnerClient.cpp:(.text+0x3a7a): undefined reference to `select@20' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: TestRunnerClient.o: bad reloc address 0x2 in section `.text$_ZN7CppUnit12TestListenerD1Ev[__ZN7CppUnit12TestListenerD1Ev]'

  • MinGWのg++で分割コンパイルエラー

    MinGW環境でC++の勉強を始めました。 簡単なサンプルのコンパイルをしてみたのですが、ソースファイルを一括してコンパイルすると問題ないのですが、個別にコンパイルしようとするとエラーがでてしまいまいます。 原因や対処法をご存じの方がいらっしゃいましたらご教示下さい。 一括でコンパイルすると問題なし bash-3.1$ g++ -Wl,--enable-auto-import main.cpp point.cpp -lstdc++ 個別にコンパイルしようとした場合 bash-3.1$ g++ -Wl,--enable-auto-import -o main.o main.cpp C:\DOCUME~1\user\LOCALS~1\Temp\ccZrVmLp.o:main.cpp:(.text+0x16): undefined reference to `Point::Point()' C:\DOCUME~1\user\LOCALS~1\Temp\ccZrVmLp.o:main.cpp:(.text+0x32): undefined reference to `Point::Point(int, int)' C:\DOCUME~1\user\LOCALS~1\Temp\ccZrVmLp.o:main.cpp:(.text+0x3e): undefined reference to `Point::println()' C:\DOCUME~1\user\LOCALS~1\Temp\ccZrVmLp.o:main.cpp:(.text+0x4a): undefined reference to `Point::println()' collect2: ld returned 1 exit status ※ -Wl,--enable-auto-importは、他の警告を消すために入れました、無くても質問の問題に変化はありませんでした。 サンプルソース ---main.cpp--- #include<iostream> #include "point.h" using namespace std; int main(){ Point p1,p2(4,5); p1.println(); p2.println(); return 0; } ----------- ---point.h--- class Point { private: int x, y; static int count; public: Point(); Point( int, int ); void set( int, int ); void println(); }; ------------- ---point.cpp--- #include<iostream> #include"point.h" using namespace std; int Point::count; Point::Point(){ this->x = this->y = 0; ++count; } Point::Point(int ax, int ay){ this->x = ax; this->y = ay; ++count; } void Point::set( int ax, int ay ){ this->x = ax; this->y = ay; } void Point::println(){ cout << "Point(" << x << "," << y << ")" << endl; } ----------- bash-3.1$ g++ -v Using built-in specs. COLLECT_GCC=D:\MinGW\bin\g++.exe COLLECT_LTO_WRAPPER=d:/mingw/bin/../libexec/gcc/mingw32/4.5.0/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.5.0/configure --enable-languages=c,c++,ada,fortran,obj c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r untime-libs --disable-werror --build=mingw32 --pref

  • LinuxのgccのLIBパス? (類似質問)

    Linuxのgccで、LIBのパスを設定する方法が知りたいのですが、gccについて詳しい書籍やサイトがありましたら、教えてください。 例)gcc -I/usr/local/example/include test.c /tmp/ccOFpCBo.o(.text+0x26): In function `main': : undefined reference to `EXAMPLE_1' /tmp/ccOFpCBo.o(.text+0x37): In function `main': : undefined reference to `EXAMPLE_2' /tmp/ccOFpCBo.o(.text+0x48): In function `main': : undefined reference to `EXAMPLE_3' collect2: ld はステータス1で終了しました。 また、ldとはVC6++でいう LINKのことでしょうか?

  • 実行ファイルが作成環境以外のPCで実行が出来ません。

    実行ファイルが作成環境以外のPCで実行が出来ません。 現在Windowsプログラミングでアプリケーションを作成しております。 しかし作成した実行ファイルを他のPCで実行しようとすると [cygwin1.dllが見つからなかったため、このアプリケーションを開始できませんでした。アプリケーションをインストールしなおすとこの問題は解決される場合があります。] とのエラーメッセージが表示され、実行することができません。 恐らくCygwin関係のエラーだとは思うのですが、Cygwinが入っていない環境でも使用できるようにすることは出来ませんでしょうか? 必要そうな情報を下に書いておきます 作成環境:Vista Cygwin コンパイル:gcc -mwindows a.cpp a.o 実行環境:X Cygwin無し

  • WindowsXPの MinGW,コマンドラインからのgccについて

    WindowsXPの MinGW,コマンドラインからのgccについて コンパイルエラーのログのテキストファイルへの取得方法をご教授ください。

  • cygwinのgccが、エラーになってしまいます。

    テストプログラム $ cat test.c #include <stdio.h> int main (void) { printf("Hello, World!\n"); return 0; } これを、コンパイルすると $ gcc test.c gcc: error trying to exec '/usr/lib/gcc/i686-pc-cygwin/4.5.3/cc1.exe': execv: Bad address /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../libcygwin.a(libcmain.o):(.text+0xba): undefined reference to `_WinMain@16' collect2: ld はステータス 1 で終了しました と、このようなエラーが出てきました。 ファイルを確認しても、何も作られていません。 $ ls test.c 対処方法を、ご教示願います。

  • MinGWのgccでOpenMPを使う方法

    MinGWのgccでOpenMPを使いたいのですが、サンプルソースコードを以下のようにコンパイルするところでエラーとなります。 gcc -fopenmp -O2 abc.c その結果が以下のようです。 ld.exe: cannot find -lpthread pthreadがみつからないのですが、あるけど見つからないのではなく、もともとない、が正解のようです。MinGWをインストールする際、ものすごく多くのファイル選択の可能性があり、デフォルトでやると欠落してしまうんだと思います。インストールのセレクトの仕方を教えて頂ければと思います。検討がつかないぐらいセレクションのリストが長々としているので。あるいは別の解決方法でも。よろしくお願いします。

専門家に質問してみよう