cantera with c++

446 views
Skip to first unread message

refikalp...@gmail.com

unread,
Dec 19, 2020, 12:46:10 PM12/19/20
to Cantera Users' Group
Hello Everyone,

I would like to use cantera from C++ but cannot manage to figure it out as i had very very hard time understanding what to do.

Is it possible for me to use Cantera with visual studio 2019 ?
Can't i just clone the cantera from github and download to visual studio ?
Would it be compiled then ?

Im sorry as im sure this is very basic but i am very perplexed by source code compilation instructions. Any help to guide me on what to do here is greatly appriciated..

Refik

Ingmar Schoegl

unread,
Dec 20, 2020, 10:27:17 AM12/20/20
to Cantera Users' Group
Dear Refik,

The short answer is no: Cantera uses a platform-independent build chain (scons), and it is currently not set up to 'just load and compile' with Visual Studio.

I have written up some instructions on how to get things to build *with* Visual Studio (although this doesn't require opening the VS IDE), see https://gist.github.com/ischoegl/ab777f871a48d7f40ecc32c1c849faa3 . I am sure there is a way to integrate things further with VS, but I haven't looked beyond simple compilation. Hope this provides some answers,

-ingmar-

PS: There was a recent discussion on the user group about a related issue, see https://groups.google.com/g/cantera-users/c/T9t5OfTV1QA/m/2s5gj9TuAQAJ

Refik Alper Tuncer

unread,
Dec 20, 2020, 12:18:35 PM12/20/20
to canter...@googlegroups.com
Dear Sir,

I am trying your instructions and started by installing Anaconda from the provided link.
However i cannot seem to get the command "(base) > conda update --all" to work. 
On which command prompt should i enter this line ? 

Also i get error when i enter the command into Anaconda Powershell
(base) PS <path>> . %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" 

The error is :

At line:1 char:8
+ (base) PS <path>> . %comspec% /k "C:\Program Files (x86)\Microsoft Vi ...
+        ~~
Unexpected token 'PS' in expression or statement.
At line:1 char:11
+ (base) PS <path>> . %comspec% /k "C:\Program Files (x86)\Microsoft Vi ...
+           ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Have you encountered this before?

Best regards.

Refik 



Ingmar Schoegl <isch...@gmail.com>, 20 Ara 2020 Paz, 18:27 tarihinde şunu yazdı:
--
You received this message because you are subscribed to a topic in the Google Groups "Cantera Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cantera-users/gS0F2MpvRvc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/de079e4b-5117-4977-a560-049241afddffn%40googlegroups.com.

Ingmar Schoegl

unread,
Dec 20, 2020, 1:08:58 PM12/20/20
to Cantera Users' Group
Dear Refik,

The way I typed instructions, the command prompt is included; the actual command starts after the '>' character. I.e. for the conda command, just skip '(base) >' (which should look the same on your powershell). For the other command, the actual input starts after '(base) PS <path>>'

-is-

Refik Alper Tuncer

unread,
Dec 20, 2020, 1:22:25 PM12/20/20
to canter...@googlegroups.com
Dear Sir,

Thank you. I managed move forward a lot. 
At the moment, i am the step where i have to get "scons build" to work but when i run the command it gives me the following error message now:

scons: Reading SConscript files ...
INFO: SCons is using the following Python interpreter: C:\Users\Refik Alper\anaconda3\envs\cantera-dev\python.exe
  File "<string>", line 1

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

which i think is related to Python strings where chars / or \ is problem but my Python knowledge is zero so i am trying to figure out how to overcome this error and complete the build.

Thank you for your help.

Best regards.

Refik

Ingmar Schoegl <isch...@gmail.com>, 20 Ara 2020 Paz, 21:09 tarihinde şunu yazdı:

Refik Alper Tuncer

unread,
Dec 20, 2020, 1:49:19 PM12/20/20
to canter...@googlegroups.com
Hello,

I managed to solve the problem by putting an "r" in front of the texts. That started the build but now when i run the command "scons install", following error pops up:

(cantera-dev) PS C:\Users\Refik Alper\GitHub\cantera> scons build

scons: Reading SConscript files ...
INFO: SCons is using the following Python interpreter: C:\Users\Refik Alper\anaconda3\envs\cantera-dev\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:
    prefix = 'C:\\Users\\Refik Alper\\GitHub\\cantera'
    boost_inc_dir = 'C:\\Users\\Refik Alper\\anaconda3\\envs\\cantera-dev\\Library\\include'

Checking for C++ header file cmath... yes
Checking for C++ header file fmt/ostream.h... no
INFO: Using private installation of fmt library.
INFO: Could not find version of fmt
Checking for C++ header file yaml-cpp/yaml.h... no
INFO: Using private installation of yaml-cpp library.
Checking for C++ header file gtest/gtest.h... no
Checking for C++ header file gmock/gmock.h... no
INFO: Using Googletest from Git submodule
Checking for C++ header file Eigen/Dense... no
INFO: Using private installation of Eigen.
INFO: Found Eigen version
Checking whether __GLIBCXX__ is declared... no
Checking whether _LIBCPP_VERSION is declared... no
Checking whether __clang__ is declared... no
INFO: Found Boost version
ERROR: Boost could not be found. Install Boost headers or set 'boost_inc_dir' to point to the boost headers.
See 'config.log' for details.

So im guessing i need to correct a path somewhere for the boost. 

Refik

Refik Alper Tuncer <refikalp...@gmail.com>, 20 Ara 2020 Paz, 21:22 tarihinde şunu yazdı:

Ingmar Schoegl

unread,
Dec 20, 2020, 2:40:20 PM12/20/20
to canter...@googlegroups.com
Looks like progress. Regarding boost, these libraries should have been taken care of by 

conda create -n cantera-dev scons numpy cython ruamel_yaml libboost h5py ipython
However, windows environments differ so it’s hard to tell. Best,
-is-

Refik Alper Tuncer

unread,
Dec 20, 2020, 3:01:36 PM12/20/20
to canter...@googlegroups.com
Dear Sir,

It should and they are actually there. I just can't understand why it can't find the boost headers in there.
Only thing that comes to my mind is im making a mistake in cantera.conf file which contains:

prefix = 'C:/Users/Refik Alper/GitHub/source'
boost_inc_dir = 'C:/Users/Refik Alper/anaconda3/envs/cantera-dev/Library/include'

What else could be wrong regarding windows environments ?

Best regards.

Refik

Ingmar Schoegl <isch...@gmail.com>, 20 Ara 2020 Paz, 22:40 tarihinde şunu yazdı:

Ingmar Schoegl

unread,
Dec 20, 2020, 7:19:48 PM12/20/20
to Cantera Users' Group
Dear Refik,

Did you check the contents of
boost_inc_dir = 'C:/Users/<user name>/anaconda3/envs/cantera-dev/Library/include'
i.e. whether this actually exists? Another possible hiccup could be the whitespace in 'Refik Alper' ... whitespaces are often an issue. You could try to escape it as 'Refik\ Alper'. Beyond, I don't have many ideas.

-is-

Refik Alper Tuncer

unread,
Dec 21, 2020, 4:41:53 AM12/21/20
to canter...@googlegroups.com
Dear Sir,

I move the boost library to a location where it won't have to go through a username (directly under C) and it still gives the same error.
I think it just does not see the path at all. I am at a loss at this point.

Thank you for your suggestions and help.

Best regards.

Refik

Ingmar Schoegl <isch...@gmail.com>, 21 Ara 2020 Pzt, 03:19 tarihinde şunu yazdı:

Refik Alper Tuncer

unread,
Dec 21, 2020, 5:45:34 AM12/21/20
to canter...@googlegroups.com
Hello,

I checked the config.log file and i think i might have located a problem.
From what i understand, there is an encoding problem in boost header files because they all give out the same error:


File "C:\Users\Refik Alper\anaconda3\envs\cantera-dev\lib\encodings\cp1254.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 79: character maps to <undefined>
scons: Configure: no

This pile of error is recorded for everything that needs to be read during building. Checked the internet and found that it had something to do with encoding type.
I just need to figure out where this line is called so that I can check or edit the code to fix it.

Refik






Refik Alper Tuncer <refikalp...@gmail.com>, 21 Ara 2020 Pzt, 12:41 tarihinde şunu yazdı:

Ingmar Schoegl

unread,
Dec 21, 2020, 8:01:10 AM12/21/20
to Cantera Users' Group
There may be an issue with the encoding of your cantera.conf file, which may depend on how you created it. I’m not sure what editor you used, but there should be a way to check (and change) it.
-is-

Refik Alper Tuncer

unread,
Dec 21, 2020, 8:10:30 AM12/21/20
to canter...@googlegroups.com
Dear Sir,

It was empty at first. Then i edited with notepad++ to include prefix and boos_inc_dir.
Encoding of the config file is UTF-8.

Refik

Ingmar Schoegl <isch...@gmail.com>, 21 Ara 2020 Pzt, 16:01 tarihinde şunu yazdı:

refikalp...@gmail.com

unread,
Dec 21, 2020, 3:21:25 PM12/21/20
to Cantera Users' Group
Dear Sir,

I successfully built and installed cantera through your instructions.
Formatted my laptop and just re-installed everything from scratch.

So how can i run cantera from my visual studio 2019 ?
I tried to run the command denev and code but it doesnt seem to recognize these commands.

Best regards.

Refik


21 Aralık 2020 Pazartesi tarihinde saat 16:10:30 UTC+3 itibarıyla refikalp...@gmail.com şunları yazdı:

Ingmar Schoegl

unread,
Dec 21, 2020, 4:52:13 PM12/21/20
to canter...@googlegroups.com
Great, I’m happy to hear that you goth things installed! Regarding next steps, you’d have to add devenv to your path variable (I believe you can find instructions online). For compiling C++ you’d have to create projects that correspond to existing makefiles... haven’t done this myself, but it should be similar to any other VS C++ project at that point.

-Ingmar-

Refik Alper Tuncer

unread,
Dec 22, 2020, 2:14:44 AM12/22/20
to canter...@googlegroups.com
Dear Sir,

I took care of the env. variables now devenv runs smoothly from anaconda shell. 

Now as for the makefiles, could you please elaborate a bit more on how to make use of cantera makefile within a vs project? I never had to deal with makefiles before so i am a bit confused at the moment. 

Earlier with boost libraries, i just added lib and header paths to preferences of the project file but im guessing it wont be as simple with cantera. 

Best regards.

Refik


22 Ara 2020 Sal 00:52 tarihinde Ingmar Schoegl <isch...@gmail.com> şunu yazdı:

Ingmar Schoegl

unread,
Dec 22, 2020, 10:01:57 AM12/22/20
to Cantera Users' Group
Dear Refik,

I don't have much information to go from (as mentioned, I haven't investigated this before), but I assume that it won't be much more complicated than adding lib and header paths as usual.

A good starting point would be cantera's C++ samples (https://github.com/Cantera/cantera/tree/main/samples/cxx). From scons (i.e. the regular cantera build tool), you can build them using `scons samples`. Once built, you can find information for individual samples in each of the subfolders of build/samples/cxx. Information on libraries, headers etc is in `Makefile` and `SConstruct` ... you'll have to piece that together, but it shouldn't be too difficult. Good luck!

-ingmar-

refikalp...@gmail.com

unread,
Dec 22, 2020, 1:53:05 PM12/22/20
to Cantera Users' Group
Dear Sir,

I am afraid i was not able to progress further.
I just can't seem to wrap my head around what to do. Cantera is built & installed and tested.
Yes, there are Cmakelist.txt files in each sample but when i open the sample example folder (for instance demo), all kinds of errors regarding cmake pops up.
Isn't there a more direct way to simply open up an environment in visual studio where i can add cantera libraries ?
Or simply start a new project where i can link cantera headers and library ?

Am i missing something obvious ?
Is there anybody who managed to get cantera to run on visual studio ?

Best regards.

Refik




22 Aralık 2020 Salı tarihinde saat 18:01:57 UTC+3 itibarıyla Ingmar Schoegl şunları yazdı:

Ingmar Schoegl

unread,
Dec 22, 2020, 9:32:54 PM12/22/20
to Cantera Users' Group
I think creating a new project where you add existing code and add link cantera headers and libraries is what I was suggesting earlier. Please make sure to open the sample folder in the 'build' directory as the other files are just templates that do not contain useful information. Regarding VS, at this point it should not be any different from any other C++ project you would deal with; the important thing is that you have all libraries and headers installed correctly, and you do have examples to start with. Unfortunately there aren't any .vcxproj files to go from, but they should not be difficult to create based on what you have at this point. Best,

-is-

refikalp...@gmail.com

unread,
Dec 23, 2020, 12:00:34 PM12/23/20
to Cantera Users' Group
Dear Sir,

Thank you for bearing with me for last couple of days. I am greatly thankful to you.

Well i guess finally i did it.
I can now call cantera headers and libraries from my main file. It builds and compiles very well.
For others who may be as confused as i was, what i did was i created a Cmakelist.txt file and empty cpp file inside a folder in cxx/samples. I downloaded cmake and just include the folder i created as source file and just let it configure it.
Rest of the compilation problems were easy to deal with some further digging in internet as it no longer was about cantera.

At the moment i am trying to figure out how i can edit or add to library files because i want to create my own equation of state and thermodynamic properties.

Best regards.

Refik



23 Aralık 2020 Çarşamba tarihinde saat 05:32:54 UTC+3 itibarıyla Ingmar Schoegl şunları yazdı:

Liang Ji

unread,
May 1, 2023, 9:39:48 PM5/1/23
to Cantera Users' Group
Hi Refik,

Sorry to bother you after 3 years. I am just wondering if you find the way to edit or add file to library or cpp file. I have a same question. 

Best Regards
Liang

Reply all
Reply to author
Forward
0 new messages