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標準の使用と関係がありますか?