issues for calling cantera from fortran

217 views
Skip to first unread message

pan....@gmail.com

unread,
Aug 26, 2022, 3:37:42 AM8/26/22
to Cantera Users' Group
Hello All, 

I am recently just installing Cantera in a new HPC by using Anaconda, by following the instruction in Cantera website.  Since I was using a Fortran77 based code to call Cantera for my simulation, I modified my own demo_ftnlib.cpp and other relative codes. All of these code ran well in another HPC in my previous university. 

in the old HPC, cantera/.experimental-2.2.1 is used. However, all the packages were installed by the University staff. So I never install them by myself before.

Now, in the new HPC, I am using Anaconda3-2021.11-Linux-x86_64 to install Cantera by default instruction, but the code cannot be complied successfully. 

The Makefile is attached, and the errors when 'make' it are as follows:

g++  -I/beegfs/home/00035/anaconda3/envs/ct-dev/include  -I/beegfs/home/00035/anaconda3/envs/ct-dev/include -I/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/include   -c -o demo_ftnlib.o demo_ftnlib.cpp
In file included from /usr/include/c++/4.8.2/cstdint:35:0,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/ext/fmt/format.h:39,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/base/fmt.h:23,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/base/ctexceptions.h:14,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/Phase.h:12,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/ThermoPhase.h:14,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/IdealGasPhase.h:14,
                 from demo_ftnlib.cpp:31:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
In file included from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/base/fmt.h:4:0,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/base/ctexceptions.h:14,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/Phase.h:12,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/ThermoPhase.h:14,
                 from /beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/thermo/IdealGasPhase.h:14,
                 from demo_ftnlib.cpp:31:
/beegfs/home/00035/anaconda3/envs/ct-dev/include/cantera/base/ct_defs.h:35:12: error: ‘std::shared_ptr’ has not been declared

.........................

It seems like I didn't install cantera fortran interface successfully?  or there are some other issues?  Any solutions? 

Thank you very much for the help.

Regards,
Eric
Makefile

Ingmar Schoegl

unread,
Aug 26, 2022, 7:22:09 AM8/26/22
to Cantera Users' Group

Dear Eric,

The stable conda packages are compiled without Fortran support (there is ongoing work to change this for the development version, see https://github.com/Cantera/conda-recipes/pull/35). You may also have to install libcantera-devel.

-ingmar-

Ray Speth

unread,
Aug 26, 2022, 9:46:43 PM8/26/22
to Cantera Users' Group

Hi Eric,

The problem is that the Makefile template provided with Cantera examples isn’t correct for your rather old version of GCC (GCC 4.8 was released in 2013). The error message listed can be resolved by adding the line

CXXFLAGS=-std=c++11

to the block of definitions in the Makefile.

Ingmar’s suggestion is relevant if you want to use the Cantera Fortran 90 interface. The method of calling Cantera from Fortran 77 used here in demo_ftnlib.cpp does not require any specific support to be compiled as part of the base Cantera library.

Regards,
Ray

pan....@gmail.com

unread,
Aug 30, 2022, 2:32:01 AM8/30/22
to Cantera Users' Group
Dear Ray,

Many thanks for your help.  I added the command to Makefile, but it still gives an error that: 
ifort  -o demotest demotest.o demo_ftnlib.o -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib -lcantera_fortran -lcantera -L/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib -Wl,-rpath,/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib  -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib  -lpthread -lstdc++
ld: cannot find -lcantera_fortran
make: *** [demotest] Error 1


Here is the content in ct-dev/lib directory, and there isn't lcantera_fortran file, so I am not sure if it is because my cantera package is not installed correctly for fortran interface/module? 

image.png

I really appreciate all your help, and look forward to hearing from you for more information. Thank you.

Regards,
Eric

pan....@gmail.com

unread,
Aug 30, 2022, 2:34:39 AM8/30/22
to Cantera Users' Group
Dear Ingmar,

Many thanks for your information.  I actually installed the development version as well by typing "conda create --name ct-dev --channel cantera/label/dev libcantera-devel" suggested in Cantera web. 

ct-env.png

It still has the errors to find the required package, as shown in my previous email to Ray.  

I am not sure if I didnt install the package correctly or not. 

Regards,
Eric

Ingmar Schoegl

unread,
Aug 30, 2022, 11:46:26 AM8/30/22
to Cantera Users' Group
Hi Eric,

I looked into this and found another issue in the Makefile: "-lcantera_fortran" is not required for F77 (this refers to the F90 module which is indeed not installed). Removing this requires digging into `Cantera.mak`, where you will find it being listed for CANTERA_CORE_FTN.

I am currently still in the process of debugging some of those Makefiles (especially Fortran ones appear to be rarely used); on the upside, all examples are continuously tested, so we know that they work if the correct flags are set. I updated the development package on conda this morning, so you should be able to pull the newest version (I think this is the first one containing F90). It should, however, be possible to get everything to run with the 'stable' 2.6.0 by tweaking the Makefile.

-ingmar- 

pan....@gmail.com

unread,
Sep 1, 2022, 9:23:44 AM9/1/22
to Cantera Users' Group
Hi Ingmar,

I am not sure why the one I installed doesnt work for my fortran code.  Actually as I mentioned in the very first post, when I worked as a PhD student, the University installed Cantera 2.2.1- experimental version and eariler version in HPC which worked well for my code for the past years since 2016. At that time, Ray actually helped a lot to debug my fortran code and link it with cantera by the demo_ftnlib.cpp file. 
Following is the installed dependences in that HPC: 
module load intel/2018.2
module load python/2.7.14-anaconda5.1.0
module load sundials/2.6.0
module load cantera/.experimental-2.2.1


The Old makefile is: 
include ${SCINET_CANTERA_ROOT}/include/cantera/Cantera.mak
FC=mpiifort
RM=rm -f
FFLAGS=-g -O3
LDFLAGS=
LDLIBS=$(CANTERA_FORTRAN_LIBS)
CPPFLAGS=$(CANTERA_INCLUDES) -O3

OBJS=kiva3_cantera_MPI.o demo_ftnlib.o
all: demo
demo: $(OBJS)
    $(FC) $(LDFLAGS) -o demo $(OBJS) $(LDLIBS)
clean:
    $(RM) $(OBJS)
dist-clean: clean
    $(RM) *~


Then after make the code, it was complied successfully with following info:

ifort -g -O3  -c -o demo.o demo.f

icpc  -I/scinet/niagara/software/2018a/opt/intel-2018.2/cantera/2.2.1/include -I/scinet/niagara/software/2018a/opt/intel-2018.2/sundials/2.6.0/include -I/scinet/niagara/software/2018a/opt/intel-2018.2/boost/1.66.0/include  -O3  -c -o demo_ftnlib.o demo_ftnlib.cpp

ifort  -o demo demo.o demo_ftnlib.o -L/scinet/niagara/software/2018a/opt/intel-2018.2/cantera/2.2.1/lib -lcantera_fortran -lcantera  -L/scinet/niagara/software/2018a/opt/intel-2018.2/sundials/2.6.0/lib -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -L/scinet/niagara/intel/2018.2/compilers_and_libraries_2018.2.199/linux/mkl/lib/intel64 -lmkl_gf_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl  -lpthread -lstdc++

Here, it finds -lcantera_fortran sucessfully and then run well.

As I have left and enter a new University, I am not allowed to use that the account in near future, and thus I need to install the Cantera in my new account in the new School. Actually, this is the very first time for me to install cantera by myself, and hence, I am not sure how and if I installed it correctly.  But I think cantera should work well with my fortran code.  

For those reasons, I am acutally a newer for installing cantera and not quite get your point, and not sure how and what I should do to fix this issue. 

Regards,

Eric

Ray Speth

unread,
Sep 1, 2022, 10:02:38 AM9/1/22
to Cantera Users' Group

Eric,

The key difference is that the copy of Cantera that you were on your old HPC cluster using was compiled with F90 support, while the copy you have installed from Conda does not, and there is a bug in the sample build scripts in this scenario. You can work around it by either modifying the Cantera.mak file installed with Cantera to remove reference to the -lcantera_fortran library, as suggested by Ingmar, or you can edit your Makefile to override the variable that would normally trigger linking to this non-existent library. I think this second option may be easier for you, and can be accomplished by adding the line:

CANTERA_CORE_FTN=-L${HOME}/anaconda3/envs/ct-dev/lib -lcantera -lyaml-cpp

to your Makefile near the top with the other variable declarations. Of course, in this case if you modify your Cantera installation path you will need to update this file as well.

Regards,
Ray

pan....@gmail.com

unread,
Sep 1, 2022, 10:38:47 AM9/1/22
to Cantera Users' Group
Hi Ray,

Many thanks for the suggestions.  I quickly tried both options.  

1) adding the suggested link in Makefile, and it gives the errors:

ifort  -o demotest demotest.o demo_ftnlib.o -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib -lcantera -lyaml-cpp -L/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib -Wl,-rpath,/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib  -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib  -lpthread -lstdc++
ld: cannot find -lyaml-cpp

make: *** [demotest] Error 1


2) modified the Cantera.mak file by disabling the CANTERA_CORE_FTN, and it shows

ifort -g  -c -o isentropic.o isentropic.f
cc   isentropic.o   -L/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib -Wl,-rpath,/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib  -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib  -lpthread -lstdc++ -o isentropic
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
isentropic.o: In function `MAIN__':
/beegfs/home/00035/canteratest/isentropic.f:13: undefined reference to `for_set_reentrancy'
/beegfs/home/00035/canteratest/isentropic.f:19: undefined reference to `newidealgasmix_'
/beegfs/home/00035/canteratest/isentropic.f:22: undefined reference to `setstate_tpx_string_'
/beegfs/home/00035/canteratest/isentropic.f:25: undefined reference to `entropy_mass_'
/beegfs/home/00035/canteratest/isentropic.f:26: undefined reference to `enthalpy_mass_'
/beegfs/home/00035/canteratest/isentropic.f:27: undefined reference to `pressure_'
/beegfs/home/00035/canteratest/isentropic.f:34: undefined reference to `setstate_sp_'
/beegfs/home/00035/canteratest/isentropic.f:35: undefined reference to `enthalpy_mass_'
/beegfs/home/00035/canteratest/isentropic.f:36: undefined reference to `density_'
/beegfs/home/00035/canteratest/isentropic.f:47: undefined reference to `temperature_'
/beegfs/home/00035/canteratest/isentropic.f:53: undefined reference to `for_write_seq_fmt'
/beegfs/home/00035/canteratest/isentropic.f:53: undefined reference to `for_write_seq_fmt_xmit'
/beegfs/home/00035/canteratest/isentropic.f:53: undefined reference to `for_write_seq_fmt_xmit'
/beegfs/home/00035/canteratest/isentropic.f:53: undefined reference to `for_write_seq_fmt_xmit'
isentropic.o: In function `soundspeed_':
/beegfs/home/00035/canteratest/isentropic.f:63: undefined reference to `cp_mass_'
/beegfs/home/00035/canteratest/isentropic.f:63: undefined reference to `cv_mass_'
/beegfs/home/00035/canteratest/isentropic.f:64: undefined reference to `temperature_'
/beegfs/home/00035/canteratest/isentropic.f:65: undefined reference to `meanmolarmass_'
collect2: error: ld returned 1 exit status
make: *** [isentropic] Error 1


For this test, I copied the example files for fortran 77

error.jpg
It seems the demo_ftnlib.cpp doesnt work. 

Any suggestions? 

Thanks a lot.

Regards,
Eric

pan....@gmail.com

unread,
Sep 1, 2022, 10:44:34 AM9/1/22
to Cantera Users' Group
Hi Ray

Futhermore, by using 2) method mentioned in last post, I also test the demo.f code for fortran77, and it shows the similar errors:

ifort -g  -c -o demotest.o demotest.f
g++ -std=c++11 -I/beegfs/home/00035/anaconda3/envs/ct-dev/include  -I/beegfs/home/00035/anaconda3/envs/ct-dev/include -I/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/include   -c -o demo_ftnlib.o demo_ftnlib.cpp
ifort  -o demotest demotest.o demo_ftnlib.o  -L/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib -Wl,-rpath,/usr/share/miniconda3/conda-bld/cantera-recipe_1660178123624/_build_env/lib  -L/beegfs/home/00035/anaconda3/envs/ct-dev/lib  -lpthread -lstdc++
demo_ftnlib.o: In function `newidealgasmix_':
demo_ftnlib.cpp:(.text+0x357): undefined reference to `Cantera::newSolution(std::string const&, std::string const&, std::string const&, std::vector<std::shared_ptr<Cantera::Solution>, std::allocator<std::shared_ptr<Cantera::Solution> > > const&)'
demo_ftnlib.o: In function `nelements_':
demo_ftnlib.cpp:(.text+0x58e): undefined reference to `Cantera::Phase::nElements() const'
demo_ftnlib.o: In function `getspeciesname_':
demo_ftnlib.cpp:(.text+0x62a): undefined reference to `Cantera::Phase::speciesName(unsigned long) const'
demo_ftnlib.o: In function `setstate_try_':
demo_ftnlib.cpp:(.text+0x8c9): undefined reference to `Cantera::Phase::setState_TRY(double, double, double const*)'
demo_ftnlib.o: In function `gotmolefractions_':
demo_ftnlib.cpp:(.text+0xd7e): undefined reference to `Cantera::Phase::getMoleFractions(double*) const'
demo_ftnlib.o: In function `gotmassfractions_':
demo_ftnlib.cpp:(.text+0xda5): undefined reference to `Cantera::Phase::getMassFractions(double*) const'
demo_ftnlib.o: In function `equilibrate_':
demo_ftnlib.cpp:(.text+0xe61): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.cpp:(.text+0xf09): undefined reference to `Cantera::ThermoPhase::equilibrate(std::string const&, std::string const&, double, int, int, int, int)'
demo_ftnlib.o: In function `getreactioneqn_':
demo_ftnlib.cpp:(.text+0x1091): undefined reference to `Cantera::Kinetics::reactionString(unsigned long) const'
demo_ftnlib.o: In function `Cantera::CanteraError::~CanteraError()':
demo_ftnlib.cpp:(.text._ZN7Cantera12CanteraErrorD2Ev[_ZN7Cantera12CanteraErrorD5Ev]+0x13): undefined reference to `vtable for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0x44): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0x78): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0xa0): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0xbc): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0xdc): undefined reference to `typeinfo for Cantera::CanteraError'
demo_ftnlib.o:(.gcc_except_table+0xfc): more undefined references to `typeinfo for Cantera::CanteraError' follow
demo_ftnlib.o: In function `Cantera::CanteraError::CanteraError<>(std::string const&, std::string const&)':
demo_ftnlib.cpp:(.text._ZN7Cantera12CanteraErrorC2IIEEERKSsS3_DpRKT_[_ZN7Cantera12CanteraErrorC5IIEEERKSsS3_DpRKT_]+0x28): undefined reference to `vtable for Cantera::CanteraError'

make: *** [demotest] Error 1

Really confused. 

Regards,
Eric

Ray Speth

unread,
Sep 1, 2022, 12:25:14 PM9/1/22
to Cantera Users' Group

Hi Eric,

Sorry, I think I should not have suggested including -lyaml-cpp in my example (it was drawn from a set of files installed on my computer, where I have yaml-cpp installed as a standalone library). Please try removing it from the CANTERA_CORE_FTN variable.

To make it easier to help you, if the above does not resolve the problem, please:
(1) run make clean before running make
(2) Include the full output of the make command each time
(3) Attach the modified Cantera.mak and your current Makefile.

I do not understand how in what you have labeled as “case 2”, make is now using the wrong compiler to link the program and is not including the demo_ftnlib.o file (which is where those symbols are defined).

And in your last case, You must still have the libraries defined to include -lcantera. There is no case where that can be omitted.

Regards,
Ray

pan....@gmail.com

unread,
Sep 1, 2022, 9:20:43 PM9/1/22
to Cantera Users' Group
Hi Ray,

Thanks for the suggestions. 

Attached are the Makefile, Cantera.mak, demotest.f and demo_ftnlib.cpp used in the test case. 

Following is the commands used and error information:
error.jpg

Regards,
Eric

demotest.f
demo_ftnlib.cpp
Cantera.mak
Makefile

Ray Speth

unread,
Oct 19, 2022, 4:42:12 PM10/19/22
to Cantera Users' Group

Hi Eric,

To keep the context for this in one place, I’m replying here rather than to your more recent re-post.

I don’t understand what’s happening here — the linker seems to be finding some but not all of the Cantera functions that are called from the code being compiled. I’m wondering if they actually all exist in the Cantera library file, or if the right library file is being linked. Can you provide the output from each of the following:

(a) Edit your Makefile to specify LDFLAGS=-Wl,--verbose, and then re-run the build process and save the output, e.g.

make clean
make > buildlog.txt 2>&1

(b) Run the command:

nm -a /beegfs/home/00035/anaconda3/envs/ct-dev/lib/libcantera.a | grep Cantera > symbols.txt

and provide the two output files (buildlog.txt and symbols.txt).

Regards,
Ray

pan....@gmail.com

unread,
Oct 19, 2022, 11:50:13 PM10/19/22
to Cantera Users' Group
Hi Ray,

Many thanks for your help. 

First of all, I am not an expert on Linux and HPC, so I am not sure if I did right by just adding sentence "LDFLAGS=-Wl,--verbose" to my Makefile directly, which thereby looks like:

include ${HOME}/anaconda3/envs/ct-dev/include/cantera/Cantera.mak
FC=ifort
RM=rm -f
FFLAGS=-g
LDFLAGS=-Wl,--verbose
CXXFLAGS=-std=c++11
LDLIBS=$(CANTERA_FORTRAN_LIBS)
CPPFLAGS=$(CANTERA_INCLUDES)

OBJS=demotest.o demo_ftnlib.o

all: demotest

demotest: $(OBJS)
    $(FC) $(LDFLAGS) -o demotest $(OBJS) $(LDLIBS)

clean:
    $(RM) $(OBJS)

dist-clean: clean
    $(RM) *~


Then, I followed your instructions by typing the commands step by step to get the two output files as attached: 

(base) [00035@mu01 canteratest]$ make clean
rm -f demotest.o demo_ftnlib.o
(base) [00035@mu01 canteratest]$ make > buildlog.txt 2>&1
(base) [00035@mu01 canteratest]$ nm -a /beegfs/home/00035/anaconda3/envs/ct-dev/lib/libcantera.a | grep Cantera > symbols.txt
(base) [00035@mu01 canteratest]$


So please take a look at the output files.  Thanks a lot for your time. 

Regards,
Eric
symbols.txt
buildlog.txt

Ray Speth

unread,
Oct 25, 2022, 12:08:49 PM10/25/22
to Cantera Users' Group
Hi Eric,

Thanks for providing this additional information. I think that trying to link a copy of the Cantera library that was compiled with a recent version of GCC while using the very outdated GCC 4.8 on your system is leading to incompatibilities that cannot be fixed. Specifically, the Cantera library included in the Conda package uses a newer ABI from libstdc++ which is not available in GCC 4.8 (as far as I understand it).

I think you will need to find a way to install a more recent version of GCC, and either use that with the Cantera conda package or compile Cantera yourself using this compiler. I'm not sure whether you will also need to use a different / more recent version of ifort -- I know it also has compatibility requirements regarding the GCC version.

Regards,
Ray
Reply all
Reply to author
Forward
0 new messages