アプリ版:「スタンプのみでお礼する」機能のリリースについて

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

A 回答 (2件)

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

    • good
    • 0
この回答へのお礼

ご回答ありがとうございます。
(長時間、放置してすみませんでした。)

C++関数をdllにしてあげたらうまくいきました。

参考
http://d.hatena.ne.jp/arakik10/20100525/p1

お礼日時:2010/08/16 09:05

どこまで効いてるかわかりませんが。


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

この回答への補足

ご回答、有難うございます。

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'

補足日時:2010/06/28 02:18
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!