Compiling Cantera C++ Programs in Windows 10

300 views
Skip to first unread message

Mario Hernandez

unread,
Aug 2, 2021, 10:01:31 AM8/2/21
to Cantera Users' Group
Dear all,

I've ben having troubles compiling some C++ programs, and I hope you can help  me to figure out the problem. The problem is the following^
  1. I downloaded Cantera using Conda: conda create --name ct-env --channel cantera cantera ipython matplotlib jupyter
  2. I activate the cantera environment:  conda activate ct-env
  3. I run my programm:  g++ -Wall main.c main.h liq_comp_0.c liq_comp_0.h output.c output.h evap.c evap.h liq_prop.c liq_prop.h surf_prop.c surf_prop.h lambda.c lambda.h props_calculator.cpp props_calculator.h -std=c++11 -o myEvapProgram $(pkg-config --cflags --libs cantera
  4. After that, I get the following error: 
  • g++: error: $(pkg-config: No such file or directory
  • g++: error: cantera): No such file or directory
  • g++: error: unrecognized command line option '--cflags'
  • g++: error: unrecognized command line option '--libs'
I would really appreciate your help.

Thanks in advance!

Mario

Bryan Weber

unread,
Aug 2, 2021, 12:02:44 PM8/2/21
to Cantera Users' Group
Hi,

I see two problems here:

1) The Conda package does not include the header files for Cantera, only the Python interface
2) If you're on Windows 10, it is unlikely that you have g++ or pkg-config installed, unless you either installed MinGW or are using WSL. In either case, including that information would be imperative to help you.

To resolve the first problem, the easiest way is to build Cantera from source. See here for more instructions: https://cantera.org/compiling/installation-reqs.html#sec-windows

Best,
Bryan

Mario Hernandez

unread,
Aug 3, 2021, 9:36:50 AM8/3/21
to Cantera Users' Group
Dear Bryan,

Thank you very much for your time and help.

I downloaded the most recent source .zip file from Github and extracted the contents. When trying to build and install Cantera, I got the following error:

C:\Users\User\Downloads\cantera>scons build
scons: Reading SConscript files ...
INFO: SCons is using the following Python interpreter: c:\users\user\appdata\local\programs\python\python39\python.exe
INFO: Compiling for architecture: amd64
INFO: Compiling using the following toolchain(s): ['mingw', 'f90']
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 0: invalid continuation byte:
  File "C:\Users\User\Downloads\cantera\SConstruct", line 195:
    env = Environment(tools=toolchain+['textfile', 'subst', 'recursiveInstall', 'wix', 'gch'],
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Environment.py", line 1010:
    apply_tools(self, tools, toolpath)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Environment.py", line 116:
    _ = env.Tool(tool)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Environment.py", line 1879:
    tool(self)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Tool\__init__.py", line 273:
    self.generate(env, *args, **kw)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Tool\mingw.py", line 155:
    SCons.Tool.Tool(tool)(env)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Tool\__init__.py", line 273:
    self.generate(env, *args, **kw)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Tool\gcc.py", line 56:
    version = detect_version(env, env['CC'])
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Tool\gcc.py", line 91:
    while SCons.Util.to_str(pipe.stdout.readline()):
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\SCons\Util.py", line 1937:
    return str(s, 'utf-8')

I downloaded Microsoft compilers (VS 2019). I believe that the problem is that it is trying to compile using the 'mingw'. How to change this feature to compile using VS?

Best wishes, 

Mario

Bryan Weber

unread,
Aug 3, 2021, 9:54:30 AM8/3/21
to Cantera Users' Group
Hi Mario,

You can set the "toolchain" option to "msvc", like this:

scons build toolchain=msvc

See here for all the currently supported options: https://cantera.org/compiling/config-options.html#options-list (or type "scons help")

Best,
Bryan

Mario Hernandez

unread,
Aug 3, 2021, 10:09:13 AM8/3/21
to Cantera Users' Group
Dear Bryan,

Now I got the following error:

C:\Users\User\Downloads\cantera>scons build toolchain=msvc
scons: Reading SConscript files ...
INFO: SCons is using the following Python interpreter: c:\users\user\appdata\local\programs\python\python39\python.exe
INFO: Compiling with MSVC 14.2
INFO: Compiling for architecture: amd64
INFO: Compiling using the following toolchain(s): ['default']
Configuration variables read from 'cantera.conf' and command line:
    toolchain = 'msvc'

Checking for C++ header file cmath... yes
Checking for C++ header file fmt/ostream.h... no
INFO: Using private installation of fmt library.
ERROR: fmt is missing. Install source in ext/fmt.
See 'config.log' for details.

The config.log file has the following:

file C:\Users\User\Downloads\cantera\SConstruct,line 842:
Configure(confdir = .sconf_temp)
scons: Configure: Checking for C++ header file cmath... 
.sconf_temp\conftest_4501b9bf892a8ba32d6185db437667f6_0.cpp <-
  |
  |#include <cmath>
  |
  |
cl /Fo.sconf_temp\conftest_4501b9bf892a8ba32d6185db437667f6_0_d8d4a6258de187a58cfcc5ba95d0a449.obj /c .sconf_temp\conftest_4501b9bf892a8ba32d6185db437667f6_0.cpp /EHsc /MD /nologo /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /O2 /Zi /Fd.sconf_temp\conftest_4501b9bf892a8ba32d6185db437667f6_0_d8d4a6258de187a58cfcc5ba95d0a449.obj.pdb /DNDEBUG
conftest_4501b9bf892a8ba32d6185db437667f6_0.cpp
scons: Configure: yes

scons: Configure: Checking for C++ header file fmt/ostream.h... 
.sconf_temp\conftest_47a251b1599bba84065578e8b262cbf9_0.cpp <-
  |
  |#include "fmt/ostream.h"
  |
  |
cl /Fo.sconf_temp\conftest_47a251b1599bba84065578e8b262cbf9_0_ab01aaac283ee5f7cae93c0c54874623.obj /c .sconf_temp\conftest_47a251b1599bba84065578e8b262cbf9_0.cpp /EHsc /MD /nologo /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /O2 /Zi /Fd.sconf_temp\conftest_47a251b1599bba84065578e8b262cbf9_0_ab01aaac283ee5f7cae93c0c54874623.obj.pdb /DNDEBUG
conftest_47a251b1599bba84065578e8b262cbf9_0.cpp
.sconf_temp\conftest_47a251b1599bba84065578e8b262cbf9_0.cpp(2): fatal error C1083: ЌҐ г¤ Ґвбп ®вЄалвм д ©« ўЄ«о祭ЁҐ: fmt/ostream.h: No such file or directory,
scons: Configure: no

And just to be clear: I am doing all of this through the Windows Command Line. Is that correct?

Sorry for many questions!

Best wishes,

Mario

Bryan Weber

unread,
Aug 3, 2021, 10:54:06 AM8/3/21
to Cantera Users' Group
Hi Mario,

The error is listed in the output:

ERROR: fmt is missing. Install source in ext/fmt.

You will need to get the source code for the fmt library, along with SUNDIALS, Eigen, yaml-cpp, and Googletest. Honestly, you will have a much easier time cloning the repository using Git, rather than downloading the Zip file of the source code, because Git automatically handles getting that source code.

Yes, all this should be done from the Windows command line :-)

Best,
Bryan

Message has been deleted
Message has been deleted

Mario Hernandez

unread,
Aug 4, 2021, 6:55:33 AM8/4/21
to Cantera Users' Group
Dear Bryan,

Finally I was able to install Cantera on my computer. However, I still get the following error message when compiling my programm: 

props_calculator.cpp:3:10: fatal error: cantera/thermo.h: No such file or directory
    3 | #include "cantera/thermo.h"
compilation terminated.

The path for the include folder is the following: C:\Users\User\Documents\cantera\include, and for the lib folder is: C:\Users\User\Documents\cantera\lib. I tried to run the programm with the following command:

g++ -Wall main.c main.h liq_comp_0.c liq_comp_0.h output.c output.h evap.c evap.h liq_prop.c liq_prop.h surf_prop.c surf_prop.h lambda.c lambda.h props_calculator.cpp props_calculator.h -std=c++11 -o myEvapProgram -I/usr/Documents/cantera/include -L/usr/Documents/cantera/lib -lcantera

I was wondering, maybe there is something wrong with the paths I chose?

Thanks you in advance!

Best wishes,

Mario

Mohammed Niyasdeen

unread,
Aug 4, 2021, 8:03:26 AM8/4/21
to Cantera Users' Group
Hi Bryan, 

I don't understand this statement from your answer, "The Conda package does not include the header files for cantera, only the Python interface". 

Because I build and installed cantera from source using the CONDA package from this link, Compile with CONDA. Then I opened Anaconda navigator, created cantera environment and launched the VScode from there (See the picture-1). 
Then I simply copy pasted the example code from this link (Example code) into the vscode environment and trying to build and run. But I keep getting this error (See the picture-2). 
Is this because of no header files for cantera in Conda package as you mentioned ?  
Picture-1.png
Picture-2.png

Bryan Weber

unread,
Aug 4, 2021, 9:33:35 AM8/4/21
to Cantera Users' Group
Hi Mario,

I'm not that familiar with MinGW, but if you used MSVC to compile Cantera, then I'm pretty sure you also need to use MSVC to compile your program. As for how to specify the include directory, it looks like you did that correctly, but I'm not sure how MinGW handles paths relative to the User directory.

Best,
Bryan

Bryan Weber

unread,
Aug 4, 2021, 9:36:10 AM8/4/21
to Cantera Users' Group
Hi,

Those instructions are for building Cantera using Conda as the Python that runs SCons. Installing the conda package means installing the pre-built package using "conda install -c cantera cantera".

Since you built the code from source, you have the header files (presuming you installed them somewhere with scons install). When you run the compiler, you need to tell it where those files are located, specifically Cantera's include and library files.

Best,
Bryan

Mario Hernandez

unread,
Aug 4, 2021, 9:39:30 AM8/4/21
to Cantera Users' Group
Dear Bryan,

How can I choose MSVC to compile my programm in the console?

Best wishes,

Mario

Bryan Weber

unread,
Aug 4, 2021, 9:44:08 AM8/4/21
to Cantera Users' Group
Hi Mario,

The MSVC C/C++ compiler is called cl.exe. I don't use Windows that often, so you'll need to look up a tutorial on how to run it, sorry :-)

Best,
Bryan

Mohammed Niyasdeen

unread,
Aug 4, 2021, 9:57:02 PM8/4/21
to Cantera Users' Group
Hi Bryan,
Thank you very much for your reply. 

My goal is to create a real-gas flamelet libraries. In order to do that I have to edit the source code. 

I tried multiple way for the past couple of weeks, and didn't make much progress. So I would like to go step-by-step. 

Can I able to edit the cantera source code if I build cantera from source using conda package using this section, Compile with CONDA ? 

I am using Windows 10, mingw. 
 
Thanks again. 
Reply all
Reply to author
Forward
0 new messages