Cantera / cantera-website

Official Cantera Website
https://cantera.org
Other
14 stars 26 forks source link

Undefined reference to xxx when compiling C++ code #228

Closed ZhuJinYu2019 closed 1 year ago

ZhuJinYu2019 commented 1 year ago

Problem description

I have installed the Cantera 3.0.0a3 successfully in WSL2. I tried to run a simple example given in https://www.cantera.org/tutorials/cxx-guide/simple-example.html#sec-cxx-simple-example. There were many errors about "undefined reference to xxx" when I compiled the code with command g++ sample.cpp -o sample -pthread -O3 -std=c++11 \ -I/usr/local/cantera/include -L/usr/local/cantera/lib \ -lcantera -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -lfmt -lyaml-cpp.

Steps to reproduce

  1. Copy the demo code in https://www.cantera.org/tutorials/cxx-guide/simple-example.html#sec-cxx-simple-example to the sample.cpp file in WSL2.
  2. Run g++ sample.cpp -o sample -pthread -O3 -std=c++11 \ -I/usr/local/cantera/include -L/usr/local/cantera/lib \ -lcantera -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -lfmt -lyaml-cpp &> log to compile the source code.
  3. See error undefined reference to xxx in log file.

Behavior

There are many errors which are posted below in the log file. /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(DenseMatrix.os): in function Cantera::ct_dgemv(ctlapack::storage_t, ctlapack::transpose_t, int, int, double, double const*, int, double const*, int, double, double*, int)': /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:227: undefined reference todgemv' /usr/bin/ld: /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:227: undefined reference to `dgemv' /usr/bin/ld: /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:227: undefined reference to dgemv_' /usr/bin/ld: /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:227: undefined reference todgemv_' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(DenseMatrix.os): in function Cantera::ct_dgetrf(unsigned long, unsigned long, double*, unsigned long, int*, int&)': /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:310: undefined reference todgetrf_' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(DenseMatrix.os): in function Cantera::ct_dgetrs(ctlapack::transpose_t, unsigned long, unsigned long, double*, unsigned long, int*, double*, unsigned long, int&)': /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:326: undefined reference todgetrs_' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(DenseMatrix.os): in function Cantera::ct_dgetrf(unsigned long, unsigned long, double*, unsigned long, int*, int&)': /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:310: undefined reference todgetrf_' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(DenseMatrix.os): in function Cantera::ct_dgetri(int, double*, int, int*, double*, int, int&)': /home/zhujinyu/cantera/include/cantera/numerics/ctlapack.h:337: undefined reference todgetri_' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(PythonExtensionManager.os): in function (anonymous namespace)::PythonHandle::~PythonHandle()': /usr/include/python3.8/object.h:478: undefined reference to_Py_Dealloc' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(PythonExtensionManager.os): in function std::_Sp_counted_ptr_inplace<(anonymous namespace)::PythonHandle, std::allocator<(anonymous namespace)::PythonHandle>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()': /usr/include/python3.8/object.h:478: undefined reference to_Py_Dealloc' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(PythonExtensionManager.os): in function (anonymous namespace)::PythonHandle::~PythonHandle()': /usr/include/python3.8/object.h:478: undefined reference to_Py_Dealloc' /usr/bin/ld: /usr/local/cantera/lib/libcantera.a(PythonExtensionManager.os): in function Cantera::PythonExtensionManager::PythonExtensionManager()': /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:75: undefined reference toPy_IsInitialized' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:110: undefined reference to PyModuleDef_Init' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:119: undefined reference toPy_BuildValue' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:127: undefined reference to _PyNamespace_New' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:136: undefined reference toPyModule_FromDefAndSpec2' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:144: undefined reference to PyModule_ExecDef' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:87: undefined reference toPy_SetProgramName' /usr/bin/ld: /home/zhujinyu/cantera/src/extensions/PythonExtensionManager.cpp:98: undefined reference to `Py_Initialize'

System information

Attachments

Additional context

Although there were information "Cantera 3.0.0a3 has been successfully installed" at the end of installation, only directory named "googletest" is in the directory cantera/build/ext/ where lacks directories fmt/, sunduals/ etc. I guess this is the problem but I'm not sure.

ischoegl commented 1 year ago

Hi @ZhuJinYu2019 ... thanks for reporting. I believe this has something to do with a recent code change, where updates are not reflected on the website yet (the newest version of Cantera needs to be linked against Python, which is the likely culprit here, although there are other changes also). One way around this would be to follow the more generic compilation instructions. For example, using pkg-config

g++ sample.cpp -o sample $(pkg-config --cflags --libs cantera)
ZhuJinYu2019 commented 1 year ago

Thank you for the reply. I still don't know how to fix the problem of the cantera 3.0.0a3, but I re-installed the cantera with version 2.6.0 and it works fine now.

ischoegl commented 1 year ago

Reopening and transferring to cantera/cantera-website