首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用gfortran链接std::basic_string时未定义的c++符号?

使用gfortran链接std::basic_string时未定义的c++符号?
EN

Stack Overflow用户
提问于 2012-12-14 16:38:27
回答 1查看 2K关注 0票数 1

我试图用我的Fortran 90程序链接一个C++文件,但是在使用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::allocator::basic_string(std::basic_string,std::basic_string::分配程序>&)”,引用自cppfile.o中的std::basic_string,std::allocator > std::operator+,std::allocator >( const*,std::basic_string,std::allocator >&&) std::basic_string,std::std::operator+> std::operator+,std::allocator >(std::basic_string,std::allocator >&&,const*) std::basic_string,std::std::operator+ >std::operator+::allocator >(std::basic_string,std::allocator >&&,std::basic_string,std::allocator >&&) std::basic_string,std::std::operator+ >std::operator+::allocator >(std::basic_string,std::allocator >&&,std::basic_string,std::allocator > const&) 组件: cppfile.o中的组件(component&&) "std::basic_string,std::allocator >::operator=(std::basic_string,std::allocator >&)“,引用如下: 函数在cppfile.o中 Component::operator=(component&)在cppfile.ld:符号(S)没有找到架构x86_64 collect2:错误: ld返回1退出状态 制作:*程序错误1

我的c++文件如下所示:

代码语言:javascript
复制
#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标准有关吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-14 19:51:09

一个解决方案似乎是从编译-std=c++11代码中删除C++。使用它,将C++代码与字符串(或包含字符串的结构)的向量相结合会导致上述错误。

我将在GCC Bugzilla中提交一个bug,并在此期间使用我的解决方案作为解决方案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13882765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档