【问题标题】:Undefined reference to `std::chrono::_V2::system_clock::now()' when linking with gfortran与 gfortran 链接时对 `std::chrono::_V2::system_clock::now()' 的未定义引用
【发布时间】:2016-10-28 14:52:16
【问题描述】:

我正在尝试在 INSEL 中创建一个用户定义的块,它需要 C++ 进行编程,我使用 gfortran 链接它。

我的程序中有以下代码

// Setting seed for random number generators
unsigned seed = static_cast<int> (std::chrono::system_clock::now().time_since_epoch().count());

设置为我的随机数生成器的种子。当我使用 g++ (gcc v.5.1.0) 编译它时,它没有显示错误或警告。我的编译命令是

g++ -O0 -Wall -c -g3 -std=c++14 -fmessage-length=0 $(sourcesC)

sourcecC 拥有我所有的 .cpp 程序。但是当我尝试使用 gfortran 链接它时:

gfortran -shared -o C:\***\inselUB.dll -Wall -L./ -linselTools $(objects) 

我收到一个错误:

C:***\resources/../src/constants.h:54: 未定义的引用 `std::chrono::_V2::system_clock::now()'

collect2.exe: 错误: ld 返回 1 退出状态 makefile:11: recipe for 目标“inselUB”失败

make: *** [inselUB] 错误 1

我只是这种接口的初学者。可能是一个简单的错误。谁能给我一个解决方案?

操作系统:Win 7

【问题讨论】:

标签: c++ linker fortran c++14 gfortran


【解决方案1】:

在将 C++ 对象与 gfortran 链接时,通常需要链接 -lstdc++。如果您使用 g++ 链接,则必须链接 -lgfortran

【讨论】:

    猜你喜欢
    • 2012-07-19
    • 2014-03-23
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多