g95プログラムからg++関数を呼び出す方法

このQ&Aのポイント
  • g95プログラムからg++関数を呼び出す方法について教えてください。
  • Fortran(g95)プログラムからg++関数を呼び出す方法がわかりません。
  • g77からC++を呼ぶことはできますが、g95からは何をするべきか教えてください。
回答を見る
  • ベストアンサー

g95プログラムからg++関数を呼び出したい。

g95プログラムからg++関数を呼び出したい。 いつもお世話になっています。 Fortran(g95)プログラムからg++関数を呼び出したいのですが、 実行できません。 どのようにすればよいか、教えて頂けませんでしょうか。 (ちなみにg77からC++を呼ぶことはできました。) ===環境設定=== OS:WindowsXP(pro) C++コンパイラ :MinGW g++ (gcc version 3.4.5) Fortranコンパイラ:MinGW g95 (gcc version 4.1.2) Fortranコンパイラ:MinGW g77 (gcc version 3.4.5) ===使用したソース=== <Fortran> ファイル名:f.f    write(*,*) "Hello Fortran World."    call funchelloc()    end ※実際には、各行先頭に半角スペース6個が入ります。 <C++> ファイル名:funcC.cpp #include <stdio.h> #include <iostream> int main(void) {   printf("hello C world!\n");   return 0; } ※見やすくするため、全角スペースでインデントしています。 ===実行手順=== >g++ -c funcC.cpp >g95 -c f.f >g95 f.o funcC.o -lstdc++ c:/mingw/lib///libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x7b): undefined reference to `_ _w32_sharedptr_unexpected' c:/mingw/lib///libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x8c): undefined reference to `_ _w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x4e): undefined reference t o `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0xb9): undefined reference t o `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x179): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x186): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1e3): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1ef): more undefined refer ences to `__w32_sharedptr' follow c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x67): undefined referen ce to `__w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x97): undefined referen ce to `__w32_sharedptr_unexpected' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xb3): undefined referen ce to `__w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text

質問者が選んだベストアンサー

  • ベストアンサー
  • Tacosan
  • ベストアンサー率23% (3656/15482)
回答No.2

それって, 単に「リンクするライブラリが不足している」だけじゃないの?

yuki7091
質問者

お礼

ご回答ありがとうございます。 (長時間、放置してすみませんでした。) C++関数をdllにしてあげたらうまくいきました。 参考 http://d.hatena.ne.jp/arakik10/20100525/p1

その他の回答 (1)

  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.1

どこまで効いてるかわかりませんが。 GCCは3までと4以降で生成するオブジェクトの仕様変更があったはずです。 gfortranとg++のバージョンを揃えるとどうでしょうか

yuki7091
質問者

補足

ご回答、有難うございます。 g++のバージョンを4.4.0に上げてみました。 しかし、うまくビルド(リンク)出来ませんでした。 >g++ -c funcC.cpp >g95 -c f.f >g95 f.o funcC.o -lstdc++ funcC.o:funcC.cpp:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' c:/mingw/lib///libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x7b): undefined reference to `_ _w32_sharedptr_unexpected' c:/mingw/lib///libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x8c): undefined reference to `_ _w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x4e): undefined reference t o `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0xb9): undefined reference t o `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x179): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x186): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1e3): undefined reference to `__w32_sharedptr' c:/mingw/lib///libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1ef): more undefined refer ences to `__w32_sharedptr' follow c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x67): undefined referen ce to `__w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x97): undefined referen ce to `__w32_sharedptr_unexpected' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xb3): undefined referen ce to `__w32_sharedptr_terminate' c:/mingw/lib///libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xd3): undefined referen ce to `__w32_sharedptr_unexpected'

関連するQ&A

  • C++の関数をfortranから呼びたい。(g++, g77)

    C++の関数をfortranから呼びたい。(g++, g77) いつもお世話になっています。 現在WindowsXPにMinGWというソフトを入れて C++のコンパイルはg++を Fortranのコンパイルはg77を 使用しています。 (いずれも動作は確認できています。) 現在、以下のようなソースを使用して fortranからC++関数を呼ぼうとしていますが できておりません。 ソース内容、コンパイル方法に問題があれば ご指摘頂きたくお願いします。 ■C++ソース #include <stdio.h> #include <iostream> extern "C" void funcHelloC_(); void funcHelloC_(void) { printf("hello C world!\n"); } ■fortranソース    write(*,*) "Hello Fortran World."    call funcHelloC()    end ※実際のソースの各文先頭には、半角スペース6つ分が  記述しています。 ■コンパイル手順 D:\C>g++ -c funcHelloC.cpp D:\C>g77 -c helloFortran.f D:\C>g77 helloFortran.o funcHelloC.o helloFortran.o(.text+0x51):helloFortran.f: undefined reference to `funchelloc_' funcHelloC.o(.text+0xd):funcHelloC.cpp: undefined reference to `_ZNKSs4sizeEv' funcHelloC.o(.text+0x60):funcHelloC.cpp: undefined reference to `_ZNKSsixEj' funcHelloC.o(.text+0x9e):funcHelloC.cpp: undefined reference to `_ZNKSsixEj' funcHelloC.o(.text+0xcc):funcHelloC.cpp: undefined reference to `_ZNKSsixEj' funcHelloC.o(.text+0x12f):funcHelloC.cpp: undefined reference to `_ZNSt8ios_base4InitC1Ev' funcHelloC.o(.text+0x14a):funcHelloC.cpp: undefined reference to `_ZNSt8ios_base4InitD1Ev'

  • WinGWのC++コンパイラの設定について

    WinGWのC++コンパイラの設定について いつもお世話になっています。 C++ソースをコンパイルできなくて困っています。 原因は何なのでしょうか。 >g++ SampleC.cc Info: resolving __fmode by linking to __imp___fmode (auto-import) Info: resolving __fpreset by linking to __imp___fpreset (auto-import) C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: warning: a uto-importing has been activated without --enable-auto-import specified on the c ommand line. This should work unless it involves constant data structures referencing symbols from auto-imported DLLs. /mingw/lib/crt2.o:crt1.c:(.text+0x37): undefined reference to `__cpu_features_in it' /mingw/lib/crt2.o:crt1.c:(.text+0x89): undefined reference to `_pei386_runtime_r elocator' fu000001.o:(.idata$2+0xc): undefined reference to `libmsvcrt_a_iname' fu000002.o:(.idata$2+0xc): undefined reference to `libmsvcrt_a_iname' fu000004.o:(.idata$2+0xc): undefined reference to `libmsvcrt_a_iname' fu000005.o:(.idata$2+0xc): undefined reference to `libmsvcrt_a_iname' nmth000000.o:(.idata$4+0x0): undefined reference to `_nm___fmode' nmth000003.o:(.idata$4+0x0): undefined reference to `_nm___fpreset' collect2: ld returned 1 exit status ソース内容 /* hello world program */ #include <stdio.h> int main(void) { printf("hello world!\n"); return 0; }

  • WindowsXPHome+MinGWでGLUTを使ったプログラムをコンパイルするには?

    http://www.rimath.saitama-u.ac.jp/lab.jp/tsakurai/opengl/index-old.htmlの > gnuwin32 (Cygwin, Mingw32, egcs) の場合: --- Obsolete !! を参考にしてlibglut32.aを作成し、MinGWフォルダの\libフォルダ内に配置しました。 また、 http://www.xmission.com/~nate/glut.html のglut-3.7.6-bin.zip (117 KB) をダウンロードして、 MinGWフォルダの\include\GLにglut.hを、system32フォルダにglut32.dllを それぞれ配置しました。 しかし必要なファイルは揃っているはずなのに http://kano.feena.jp/?OpenGL のインストール確認プログラムをMinGWのmakeでコンパイルしようとすると、 gcc -o testglut testglut.o -lglut32 -lglu32 -lopengl32 testglut.o:testglut.c:(.text+0x1c): undefined reference to `__glutInitWithExit@1 2' testglut.o:testglut.c:(.text+0x3c): undefined reference to `__glutCreateWindowWi thExit@8' testglut.o:testglut.c:(.text+0x5c): undefined reference to `__glutCreateMenuWith Exit@8' collect2: ld returned 1 exit status make: *** [testglut] Error 1 のようにエラーが出ます。 どのようにしたらよいでしょうか? GLUTを使っていないプログラムをコンパイルして問題箇所を特定しようと 思ったのですがそのようなプログラムWebにはなかったため GLUTの問題なのかそもそもOpenGLの問題なのかもよくわかりません。申し訳ありません。 どなたか教えてください。お願いします。

  • 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]'

  • FortranのG95コンパイルエラー

    お世話になります。 先日業務の参考に技術書を購入しました。 その技術書には計算するためのFotranのソースプログラムが付属されており、それを実行するためコンパイラのG95をインストールしました。 ですがコンパイルを実行すると以下のエラーが出てしまいます。 c:/g95/bin/../lib/gcc-lib/i686-pc-mingw32/4.1.2//libf95.a(main.o):(.text+0x32):undefined reference to `_MAIN_' このエラーをグーグルで「libf95.a(main.o)」をキーワードに調べてみましたが英語のページに当たり、まるで理解できませんでした。 G95は技術書の付属CDに入っていたので出来るはずなのですが。 このエラーの原因をご存知の方がいらしたらよろしくお願いします。 [追記] OSはXPのSP3です。

  • コンパイル時のエラー

    UNIXでサーバー、クライアントのCプログラミングをテキストどおりに書いてコンパイルしたのですが、以下のエラーが出ます。gcc, ccでコンパイルすると以下のようになるのですが、これはどういうことなのでしょうか?何が原因なのでしょうか?よろしくお願いいたします。 gcc unix_server.c /var/tmp/ccvpay1f1.o: In function `main': /var/tmp/ccvpay1f1.o(.text+0x8c): undefined reference to `socket' /var/tmp/ccvpay1f1.o(.text+0x104): undefined reference to `unllnk' /var/tmp/ccvpay1f1.o(.text+0x118): undefined reference to `bind' /var/tmp/ccvpay1f1.o(.text+0x150): undefined reference to `listen' /var/tmp/ccvpay1f1.o(.text+0x1a8): undefined reference to `accept' cc unix_server.c ld: /usr/lib/cmplrs/cc/crtn.o: Error: Unresolved: rindex socket bzero bcopy unllnk bind listen accept

  • Fedora7で libpthread.aをリンクすると、コンパイルエラーになってしまいました

    はじめまして、 Fedora7でマルチスレッドのプログラムをビルドし、 libpthread.aをリンクしたところ、コンパイルエラーになってしまいました。 Fedora4~5では、起きなかったため、 libpthread.aのバージョン変更により、問題がおきたのではないかと思っております。 libpthreadのバージョンは2.6-4で [root@localhost]# rpm -qf /usr/lib/libpthread.a glibc-devel-2.6-4 glibc-develをダウングレードしようと思いましたが、 glibc-commonの依存関係が厳しく、forceしてもうまくいきませんでした。 makeのエラーは下記の内容で、main.cppにlibpthread.aをリンクしてビルドすると、 libpthread.a内で使ってる関数がundefinedでこけてしまいます。 ネットを検索して、pthreadのについて書かれているサイトを読みましたが、あまり見つからずどうして良いやらわからない状態です。 ttp://uyota.asablo.jp/blog/2007/01/27/1142762 Fedora7でlibpthread.aをリンクし、 undefinedを回避して、うまくビルドする方法をご存知でしたら、お教えください。 ---------------- エラー内容 [root@localhost test]# make make clean make[1]: ディレクトリ `/src/test' に入ります rm Main.o removed `Main.o' make[1]: ディレクトリ `/src/test' から出ます make test make[1]: ディレクトリ `/src/test' に入ります g++ -c -o Main.o Main.cpp g++ -o test Main.o /usr/lib/libpthread.a -lpthread /usr/lib/libpthread.a(pthread_create.o): In function `pthread_create': (.text+0xca3): undefined reference to `_dl_stack_flags' /usr/lib/libpthread.a(pthread_create.o): In function `pthread_create': (.text+0x1126): undefined reference to `_dl_stack_flags' /usr/lib/libpthread.a(ptw-accept.o): In function `accept': (.text+0x23): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-accept.o): In function `accept': (.text+0x52): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-send.o): In function `__send': (.text+0x23): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-send.o): In function `__send': (.text+0x52): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-pause.o): In function `__pause_nocancel': (.text+0x18): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-pause.o):(.text+0x3b): more undefined references to `__syscall_error' follow /usr/lib/libpthread.a(init.o): In function `__pthread_initialize_minimal': (.text+0x16c): undefined reference to `__libc_setup_tls' /usr/lib/libpthread.a(init.o): In function `__pthread_initialize_minimal': (.text+0x328): undefined reference to `_dl_init_static_tls' /usr/lib/libpthread.a(init.o): In function `__pthread_initialize_minimal': (.text+0x34d): undefined reference to `_dl_wait_lookup_done' /usr/lib/libpthread.a(ptw-read.o): In function `__read_nocancel': (.text+0x26): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-read.o): In function `__read_nocancel': (.text+0x56): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-open.o): In function `__open_nocancel': (.text+0x26): undefined reference to `__syscall_error' /usr/lib/libpthread.a(ptw-open.o): In function `__open_nocancel': (.text+0x56): undefined reference to `__syscall_error' /usr/lib/libpthread.a(sigaction.o): In function `__libc_sigaction': (.text+0x60): undefined reference to `_dl_sysinfo_dso' /usr/lib/libpthread.a(sigaction.o): In function `sigaction': (.text+0x19a): undefined reference to `_dl_sysinfo_dso' collect2: ld はステータス 1 で終了しました make[1]: *** [test] エラー 1 make[1]: ディレクトリ `/src/test' から出ます make: *** [build] エラー 2 -- [root@localhost]# cat /etc/ld.so.conf /usr/lib include ld.so.conf.d/*.conf

  • libSDL.aをリンクしたのに参照が見つからない

    以下makeの出力です. g++ -c -g -Wall --std=c++11 -O3 `sdl-config --cflags` main.cc g++ -c -g -Wall --std=c++11 -O3 `sdl-config --cflags` myapp.cc make -C ./util make[1]: Entering directory `/home/****/####/src/util' g++ -c -g -Wall --std=c++11 -O3 rand.cc g++ -c -g -Wall --std=c++11 -O3 color.cc ar r libutil.a rand.o color.o C:\MinGW\bin\ar.exe: creating libutil.a ranlib libutil.a make[1]: Leaving directory `/home/****/####/src/util' g++ -g -Wall --std=c++11 -O3 `sdl-config --cflags` `sdl-config --libs` ./util/l ibutil.a main.o myapp.o -o ####.exe myapp.o: In function `_ZN5MyApp4execEv': C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: undefined reference to `_SDL_ Delay' C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: undefined reference to `_SDL_ Delay' C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: undefined reference to `_SDL_ Delay' C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: undefined reference to `_SDL_ Delay' C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: undefined reference to `_SDL_ Delay' myapp.o:C:\MinGW\msys\1.0\home\****\####\src/myapp.cc:29: more undefined refere nces to `_SDL_Delay' follow collect2.exe: エラー: ld はステータス 1 で終了しました make: *** [charaga.exe] Error 1 エラーのあるmyapp.ccです. #include <iostream> #include <SDL.h> #include "myapp.h" using ::std::cout; using ::std::endl; struct MyApp::Impl{ Impl(int argc, char *argv[]) { SDL_Init(SDL_INIT_TIMER); } ~Impl() { SDL_Quit(); } }; void ::MyApp::init(int argc, char *argv[]) { impl.reset(new Impl(argc, argv)); } void ::MyApp::exec() { for(int i = 0; i < 6; i++){ cout << i << "sec." << endl; SDL_Delay(1000); } } nm libSDL.aからの抜き出しです. SDL_audio.o: 000002b4 T _SDL_CloseAudio U _SDL_ConvertAudio U _SDL_CreateMutex U _SDL_CreateThread U _SDL_Delay U _SDL_DestroyMutex U _SDL_Error SDL_events.o: 00000000 t .text U _SDL_AppActiveInit U _SDL_AppActiveQuit U _SDL_CheckKeyRepeat U _SDL_CreateMutex U _SDL_CreateThread U _SDL_Delay U _SDL_DestroyMutex SDL_diskaudio.o: 00000000 D _DISKAUD_bootstrap U _SDL_Delay U _SDL_Error U _SDL_RWFromFile U _SDL_getenv U ___mingw_vfprintf U __imp___iob U _atoi SDL_dummyaudio.o: 00000000 D _DUMMYAUD_bootstrap U _SDL_Delay U _SDL_Error U _SDL_getenv U _free U _malloc SDL_dibaudio.o: 0000057c t _FillSound@20 U _GetCurrentThread@0 U _ReleaseSemaphore@12 U _SDL_CalculateAudioSpec U _SDL_Delay U _SDL_Error U _SDL_SetError SDL_systimer.o: 000000a4 T _SDL_Delay $ sdl-config --cflags --libs -I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows ご指南の方よろしくお願いします.

  • tcpserverをインストールできない。

    qmailとtcpserverでメールサーバを構築しようとしています。 qmailのほうはうまくいきました。送信はできます。 pop接続用にtcpserverを使おうとしてるんですが ucspi-tcp-0_84.tar.gzを展開して make setup check を行うと次のようなエラーメッセージが出てインストールできません。 考えられる原因はなんでしょうか? ./load tcpclient ip.o ipalloc.o dns.o remoteinfo.o \ timeoutconn.o timeoutread.o timeoutwrite.o getopt.a \ strerr.a stralloc.a env.a alloc.a ndelay.a substdio.a \ error.a str.a sig.a fd.a case.a fs.a `cat dns.lib` `cat \ socket.lib` dns.o: In function `resolve': dns.o(.text+0x11f): undefined reference to `__dn_expand' dns.o: In function `findname': dns.o(.text+0x1c1): undefined reference to `__dn_expand' dns.o(.text+0x23a): undefined reference to `__dn_expand' dns.o: In function `findip': dns.o(.text+0x2c1): undefined reference to `__dn_expand' dns.o: In function `findmx': dns.o(.text+0x3c5): undefined reference to `__dn_expand' dns.o(.text+0x460): more undefined references to `__dn_expand' follow dns.o: In function `dns_init': dns.o(.text+0x4b5): undefined reference to `__res_search' dns.o(.data+0xc): undefined reference to `__res_query' collect2: ld returned 1 exit status make: *** [tcpclient] エラー1 OSはTurboLinux7です。

  • ctime_r宣言が無いのに何故かコンパイルが通る

    MinGW 5.1.3 (Full Install) で以下のソースをコンパイルしたところ、ctime_rが何処にも宣言されていないのに何故かコンパイルが通りました。 /* a.c */ #include <time.h> int main() {  //(実行エラーにはなるはずだが、コンパイルは出来るはず)  ctime_r(NULL, NULL);  return 0; } $ gcc -v -c a.c Reading specs from C:/MyPrograms/MinGW/lib/gcc/mingw32/3.4.2/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.2 (mingw-special) cc1 -quiet -v -iprefix C:\MyPrograms\MinGW\bin\../lib/gcc/mingw32/3.4.2/ a.c -quiet -dumpbase a.c -auxbase a -version -o ./ccyAbaaa.s ignoring nonexistent directory "C:/MyPrograms/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include" ignoring nonexistent directory "/mingw/include" ignoring nonexistent directory "/mingw/include" ignoring nonexistent directory "/mingw/lib/gcc/mingw32/3.4.2/include" ignoring nonexistent directory "/mingw/mingw32/include" ignoring nonexistent directory "/mingw/include" #include "..." search starts here: #include <...> search starts here: C:/MyPrograms/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include C:/MyPrograms/MinGW/bin/../lib/gcc/mingw32/3.4.2/include End of search list. GNU C version 3.4.2 (mingw-special) (mingw32) compiled by GNU C version 3.4.2 (mingw-special). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 as -o a.o ./ccyAbaaa.s ところがリンクはエラーになります。 $ gcc -v a.o (略) ld -Bdynamic C:/MyPrograms/MinGW/lib/crt2.o C:/MyPrograms/MinGW/lib/gcc/mingw32/3.4.2/crtbegin.o -LC:/MyPrograms/MinGW/lib/gcc/mingw32/3.4.2 -LC:/MyPrograms/MinGW/lib/gcc -LC:/MyPrograms/MinGW/mingw32/lib -LC:/MyPrograms/MinGW/lib a.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt C:/MyPrograms/MinGW/lib/gcc/mingw32/3.4.2/crtend.o a.o:a.c:(.text+0x3a): undefined reference to `ctime_r' なぜコンパイルはできるんだろうと思ったのですが、やはりインクルードパスにあるヘッダ群に ctime_r らしきものはやはり見当たりません。 $ find . -type f | xargs grep "ctime_r" $ find C:/MyPrograms/MinGW/include -type f | xargs grep "ctime_r" $ find C:/MyPrograms/MinGW/lib/gcc/mingw32/3.4.2/include -type f | xargs grep "ctime_r" $ なぜコンパイルが通っているのでしょうか? [補足] このテストを行う前に GnuWin32 の libgw32c(glibc互換ライブラリで、この中のtime.hはctime_rを含む) をインストールしてコンパイル&リンクを試みましたが、やはりリンクエラーが出ていました $ gcc -I/path/to/glibc a.c -lgw32c undefined reference to `ctime_r' 今回の質問のテストを行う前にlibgw32cライブラリはアンインストールしています。

専門家に質問してみよう