使用gfortran链接c++时std::basic_string的未定义符号
Undefined symbols for std::basic_string when linking c++ using gfortran?
我正试图将C++文件与我的Fortran 90程序链接,但在使用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::allocater::basic_string(std::basic_string,std::allocater>&)",引用自:cppfile中的std::basic_string,std::allocater>std::operator+,std:::allocator>(char const*,std:,basic_string;std::分配器>&&),cppfile中的std::allocater>(std::basic_string,std::分配器>&,std::basic_string,std:分配器>&),cppfile中的std::allocator>(std::basic_string,std::分配器>&,std::basic_string,std::分配器>const&)。o
cppfle中的component::component(component&&在cppfile.o 中ld:未找到体系结构x86_64的符号
collect2:error:ld返回1退出状态
make:*[program]错误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;
}
有没有想过为什么会发生这种事?我确保链接-lsdc++库。这可能与我使用与字符串库相关的C++11标准有关吗?
一个解决方案似乎是从C++代码的编译中删除-std=c++11
。有了它,将链接C++代码与字符串向量(或包含字符串的结构)相结合会导致上述错误。
我将在GCC Bugzilla中对此提交一个错误,并在此期间使用我的解决方案作为变通方法。
- 编译C++时未定义的引用
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用
- 从 std::string 到 std::array<char,size> 的 memcopy 额外数据是否是一种未定义的行为?
- Cpp 未定义引用 'Apache:: thrift:: transport:: TSocket:: TSocket (std:: string const&, int)'
- 对"cv::String::allocate(unsigned long)"的未定义引用
- C 与stat lib中的std :: string相关的未定义符号
- 对'PreconditionViolatedException::PreconditionViolatedException(std::string const&)'的未定义引用
- 链接webrtc本机时出错,因为未定义对具有std::string的方法的引用
- 对'std::string Helper::ToString<int>(int const&)'的未定义引用
- 错误未定义对"BP::D evice::Create(std::string const&)"的引用
- 'std::string::c_str()'如何返回不会导致内存泄漏或未定义的 C 字符串内容的 C 字符串?
- 未定义对“GradeBook::GradeBook(std::string)”的引用
- 标识符[string-value]未定义
- 未定义引用 'htmlcxx::HTML::P arserDom::p arseTree(std::string const&)'
- 错误:未定义对"cv::imread(std::string const&, int)"的引用
- 对 'json11::Json::d ump(std::string&) const' collect2 的未定义引用:错误:ld 返回 1 个退出状态
- 对 std::哈希<string>的未定义引用
- 未定义的引用 cv::imread(std::string const&, int)
- 使用c_str()时std::string的未定义行为
- 对矢量<String> G++ 链接器错误的未定义引用