Undefined reference to `std::chrono::_V2::system_clock::now()' when linking with gfortran

坚强是说给别人听的谎言 提交于 2019-12-24 08:59:33

问题


I am trying to create an user defined block in INSEL which requires C++ to program and I link it using gfortran.

I have the following code in my program

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

to set as a seed to my random number generator. When i compile it using g++ (gcc v.5.1.0) it shows no error or warning. My compiling command is

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

sourcecC has all my .cpp programs. BUt when I try linking it using gfortran with:

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

I get an error:

C:***\resources/../src/constants.h:54: undefined reference to `std::chrono::_V2::system_clock::now()'

collect2.exe: error: ld returned 1 exit status makefile:11: recipe for target 'inselUB' failed

make: *** [inselUB] Error 1

I am just a beginner to this type of interfacing. may be its a simple error. Could anyone suggest me an solution?

OS: Win 7


回答1:


Normally you need to link -lstdc++ when linking C++ objects with gfortran. If you linked with g++ you would have to link -lgfortran.



来源:https://stackoverflow.com/questions/40307715/undefined-reference-to-stdchrono-v2system-clocknow-when-linking-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!