1

C++ファイルをFortran90プログラムにリンクしようとしていますが、gfortranを使用するとリンクエラーが発生します。

私のFortranファイルは次のコマンドでコンパイルされ
gfortran -c -o obj/file.o file.f90 -O0 -g3 -ffree-line-length-none -fcheck-array-temporaries -fbounds-checkます。C++ファイルは次のコマンドでコンパイルされます。g++-4.7 -c -o obj/cppfile.o cppfile.cpp -O0 -g3 -std=c++11

次に、すべてがgfortranでリンクされます。
gfortran -o program obj/file.o obj/cppfile.o -O0 -g3 -ffree-line-length-none -fcheck-array-temporaries -fbounds-check -lm -llapack -lc -lgfortran -lgcc -lstdc++

これを行うと、次のリンクエラーが発生します。

アーキテクチャx86_64の未定義のシンボル:
"std :: basic_string、std :: allocator :: basic_string(std :: basic_string、std :: allocator> &&)"、参照元:

std :: basic_string、std :: allocator> std :: operator +、std :: allocator>(char const *、std :: basic_string、std :: allocator> &&)in cppfile.o
std :: basic_string、std :: allocator > std :: operator +、std :: allocator>(std :: basic_string、std :: allocator> &&、char const *)in cppfile.o
std :: basic_string、std :: allocator> std :: operator +、std :: allocator>(std :: basic_string、std :: allocator> &&、std :: basic_string、std :: allocator> &&)in cppfile.o
std :: basic_string、std :: allocator> std :: operator +、std :: allocator >(std :: basic_string、std :: allocator> &&、std :: basic_string、std :: allocator> const&)in cppfile.o
component :: component(component &&)in cppfile.o "std :: basic_string、std ::アロケーター>::operator =(std :: basic_string、std :: allocator> &&) "、参照元:
functioncppfile.oの
component::operator =(component &&)cppfile.oの

ld:アーキテクチャx86_64のシンボルが見つかりません
collect2:エラー:ldが1の終了ステータスを返しました
make:* [プログラム]エラー1

私のc++ファイルは次のようになります。

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <vector>

using namespace std;

struct component
{
    string num;     // numerator of component
    string den;     // denominator of component
    int ind;        // index of variable
};

extern "C"{
void subroutine_ (int num, const int* array)
{
    ...
    return;
}

なぜこれが起こるのかについて何か考えはありますか?-lstdc++ライブラリをリンクするようにしました。文字列ライブラリに関連するC++11標準の使用と関係がありますか?

4

1 に答える 1

1

-std=c++111つの解決策は、C++コードのコンパイルからを削除することであるように思われます。これを使用すると、リンクC ++コードを文字列のベクトル(または文字列を含む構造体)と組み合わせると、上記のエラーが発生します。

これについてGCCBugzillaにバグを報告し、当面は解決策を回避策として使用します。

于 2012-12-14T19:51:09.137 に答える