0

I'm trying to run the test code on the Cantera website in Visual Studio 2019 but get the following error:

error LNK2001: unresolved 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@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@00AEBV?$vector@V?$shared_ptr@VSolution@Cantera@@@std@@V?$allocator@V?$shared_ptr@VSolution@Cantera@@@std@@@2@@3@@Z)
#include "cantera/base/Solution.h"
#include "cantera/thermo.h"
#include <iostream>

using namespace Cantera;

// The actual code is put into a function that can be called from the main program.
void simple_demo()
{
    // Create a new Solution object
    auto sol = newSolution("h2o2.yaml", "ohmech", "None");
    auto gas = sol->thermo();

    // Set the thermodynamic state by specifying T (500 K) P (2 atm) and the mole
    // fractions. Note that the mole fractions do not need to sum to 1.0 - they will
    // be normalized internally. Also, the values for any unspecified species will be
    // set to zero.
    gas->setState_TPX(500.0, 2.0 * OneAtm, "H2O:1.0, H2:8.0, AR:1.0");

    // Print a summary report of the state of the gas.
    std::cout << gas->report() << std::endl;
}

// The main program just calls function simple_demo within a 'try' block, and catches
// CanteraError exceptions that might be thrown.
int main()
{
    try {
        simple_demo();
    }
    catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
    }
}

I thought it was a library related issue but when when I run scons on the samples using the same library links the sample code runs successfully

SternK
  • 11,649
  • 22
  • 32
  • 46
Abi89
  • 1
  • So it works with scons but not with Visual Studio. What have you done in Visual Studio to add the cantera library to your project? – john Feb 10 '23 at 08:20
  • For example, I see the website recommends using CMake, is that what you did? – john Feb 10 '23 at 08:22
  • @john I added the include path for boost, eigen, cantera, fmt, and yaml-cpp and added the path of the libraries for those libraries (except for eigen) to the linker path. I used scons to build Cantera using the websites instructions – Abi89 Feb 10 '23 at 08:24
  • Did you also add the library to the linker settings or just the library directory? – Alan Birtles Feb 10 '23 at 08:28
  • @AlanBirtles I added the directory of the libraries via Configuration Properties->Linker->General->Additional Library Directories – Abi89 Feb 10 '23 at 08:31
  • @Abi89 You also need to add the libraries themselves, Properties->Linker->Input->Additional Dependencies – john Feb 10 '23 at 08:43
  • @john Thant worked! Thank you. Why do I have to add the .lib files for cantera, fmt, and yaml-cpp but not for boost? – Abi89 Feb 10 '23 at 08:53
  • boost makes use of MSVC's `#pragma link` functionality to automatically add link directives to the object files that use boost headers – Alan Birtles Feb 10 '23 at 10:14
  • @Abi89 Also the majority of boost is a *header only library*, no actual library is required. – john Feb 10 '23 at 10:37
  • Why can't new users figure out how to use the search capabilities of either Google or the search bar at the top of each SO page, so that they can do a basic search for the error message to find existing posts? A **simple, basic search** is part of the effort we expect you to put in to solve the problem yourself before posting here, and it's very clear you did not make that effort. – Ken White Feb 12 '23 at 00:06

0 Answers0