cantera with C++

195 views
Skip to first unread message

yecheng song

unread,
Aug 21, 2022, 7:13:55 AM8/21/22
to Cantera Users' Group
Hi therre
I want to use visual studio to run cantera's C++ examples.I followed this guide to complete the installation of cantera.https://gist.github.com/ischoegl/ab777f871a48d7f40ecc32c1c849faa3

1.png
I checked other members' posts on how to install and compile cantera using MSVC.https://groups.google.com/g/cantera-users/c/_bcq0utPjBk/m/8tafCqd_CAAJ
Initially, MSVC could not recognize the files in cantera, then I imported cantera and boost in my project and it showed success.Unresolvable external symbols appeared, and this error appeared when I ran the example, so I imported cantera.lib into the linker based on other people's modifications, and it still didn't fix the problem.
error LNK2001: 无法解析的外部符号 "(unresolvable external symbol )class std::shared_ptr<class Cantera::Solution> __cdecl Cantera::newSolution(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::shared_ptr<class Cantera::Solution>,class std::allocator<class std::shared_ptr<class Cantera::Solution> > > const &)" (?newSolution@Cantera@@YA?AV?$shared_ptr@VSolution@Cantera@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@00ABV?$vector@V?$shared_ptr@VSolution@Cantera@@@std@@V?$allocator@V?$shared_ptr@VSolution@Cantera@@@std@@@2@@3@@Z)
2.png3.png4.png

Ingmar Schoegl

unread,
Aug 21, 2022, 9:49:06 AM8/21/22
to Cantera Users' Group
At the moment, there is no support for integration of C++ examples into Visual Studio. Instead, supported options include the Make / SCons / CMake routes outlined on the website, i.e. https://cantera.org/tutorials/cxx-guide/compiling.html

If you want to set up things in VS, there is one central file that lists all dependencies and settings: include/cantera/Cantera.mak
Based on that, you should be able to piece things together. It would be great if you could post a solution as this might be of interest to other users (if possible, in plain text, not screen shots). 

-ingmar-

Rishikesh Sampat

unread,
Nov 19, 2022, 2:47:08 PM11/19/22
to Cantera Users' Group
Hello,

I am facing a similar issue. I managed to build and install Cantera from source using SCons. However, when I try to run one of the C++ examples, combustor.cpp, in Visual Studio 2022, I get an error "LNK2019: unresolved external symbol...".
I already included the Cantera "include" directory in VS under Project->Properties->VC++ Directories->Include Directories. Any ideas on why this may be occurring?

Regards,
Rishikesh

Ray Speth

unread,
Nov 23, 2022, 9:37:14 AM11/23/22
to Cantera Users' Group
Hi Rishikesh,

In addition to the include directory, you need to specify two additional things:

- Under VC++ Directories -> Library Directories, you should specify the directory that includes the "cantera.lib" file. This should be the same as the path for the "include" directory, but with "lib" instead of "include".
- Under Linker -> Input -> Additional Dependencies, you should add "cantera.lib" to the list of libraries to link.

Regards,
Ray

Rishikesh Sampat

unread,
Nov 27, 2022, 1:58:16 PM11/27/22
to Cantera Users' Group
Hi Ray,

Thanks, indeed that works. I also ended up having to add cantera_shared.lib and cantera_shared.exp, so all the files except for the .dll in Cantera\lib, under Linker->Input-> Additional Dependencies.

Kind Regards,
Rishikesh

Reply all
Reply to author
Forward
0 new messages