Compile/Linking Failed for Cantera Sample Program in Visual Studio 2015

353 views
Skip to first unread message

Nicholas Mueschke

unread,
Jul 19, 2016, 12:52:52 PM7/19/16
to Cantera Users' Group
I am trying to use Cantera and compile the simple Cantera "Hello World" program from Visual Studio and I'm have a rather difficult time.  I've tried many things at this point and I keep hitting problems.  Specifically, I'm trying to get everything compiled in a 64-bit mode.  My end goal is to link to the Cantera libraries from another 64-bit code and to have Cantera calculate reaction rates and equilibrium values.  So, I'm interested in interfacing with the Cantera libraries from a C++ interface.  To be clear, I'm not interested in modifying the Cantera source code, but rather, I just want to link to it.

It may be worth pointing out that I've successfully tested my 64 bit Cantera installation in Python 3.4 and Matlab.  I've successfully been using Cantera in Matlab to calculate some things, but now want to move to a C++ interface.


To start, my first question is this: can I simply link to the cantera.lib file that was created when I ran the Cantera Windows installed (https://github.com/Cantera/cantera/releases).  Do I need to be able to compile Cantera or do I simply need the provided Cantera include files and cantera.lib file?

Here's my basic set up:
MS Windows 7 Ultimate (64 bit)
Visual Studio 2015 Pro
Cantera 2.2.1 (64 bit)
Python 2.7, 32 bit (for SCons)
Python 3.4, 64 bit
SCons 2.4.1
Pre-build 64-bit boost libraries for MSVC-14 (include and lib directories are: C:\local\boost_1_61_0  and  C:\local\boost_1_61_0\lib64-msvc-14.0)
Sundials 2.6.1 (built with CMake, include and lib directories are: C:\sundials-2.6.2-install\include  and  C:\sundials-2.6.2-install\lib)

To try out the Cantera "Hello World" program, I create an empty C++ project.  I add the sample.cpp file to the project (http://www.cantera.org/docs/sphinx/html/cxx-guide/simple-example.html).

I switch the target platform to x64.  Under the project properties for the x64 target platform, I add the following:
- Under C/C++ --> General --> Additional Include Directories: C:\Program Files\Cantera\include, C:\local\boost_1_61_0, C:\sundials-2.6.2-install\include
- Under Linker --> General --> Additional Library Directories: C:\Program Files\Cantera\lib, C:\local\boost_1_61_0\lib64-msvc-14.0, C:\sundials-2.6.2-install\lib
- Under Linker --> Input --> Additional Dependencies:  cantera.lib



Basically... I appear to be following the set up found in this thread: https://groups.google.com/forum/#!topic/cantera-users/xERB6lv3tvg

OK, having done all of that, when I compile I get 100s of linker warnings and errors.  See attached file (Output-Build1.txt).  The linker complains about the default lib MSCVRT conflicting with other libs.  So I turned on "no default libraries" and then still receive 100s of linker errors with respect to cantera.lib.  See second attached file (Output-Build2.txt).

Does anyone have experience seeing any of these error messages in Visual Studio?  Thanks in advance for any responses.

Regards,
Nick





Output-Build1.txt
Output-Build2.txt

Ray Speth

unread,
Jul 19, 2016, 1:22:10 PM7/19/16
to Cantera Users' Group
Nick,

In principle, it is possible to link with the cantera.lib file that is distributed with the binary installers. However, this requires matching exactly the versions of the compiler and other libraries (especially Boost), which means in practice you're probably best off compiling Cantera yourself if you want to build and link a C++ application that uses Cantera.

The binaries for Cantera 2.2.1 are built using Visual Studio 2008. I don't recall which version of the Boost libraries were used.

Regards,
Ray

Bryan W. Weber

unread,
Jul 19, 2016, 1:22:19 PM7/19/16
to Cantera Users' Group
Dear Nicholas,

Why are you using 32-bit Python for SCons? If you built the Cantera library yourself, that might be the problem, since you're trying to link a 32-bit library to a 64-bit one.

If that doesn't fix it, can you please let us know where and how you installed Cantera?

Cheers,
Bryan

On Tuesday, July 19, 2016 at 12:52:52 PM UTC-4, Nicholas Mueschke wrote:

Nicholas Mueschke

unread,
Jul 19, 2016, 4:28:18 PM7/19/16
to Cantera Users' Group
Thanks for the quick response.  I've installed SCons into my 64 bit Python 2.7 installation and I'm now using that.  That hasn't remedied anything though.

First problem (maybe): 32 build of Sundials
I just re-built Sundials accoding to these instructions: http://bryanwweber.com/writing/personal/2014/08/21/how-to-install-sundials-on-windows-7/.  Sundials compiled and installed to C:\local\sundials-2.6.2-x64-install just fine, except that CMake built everything in 32 bit mode.  I've tried altering the cmake command line to use the CMAKE_CL_64 variable:

>cmake ..\sundials-2.6.2 -G "NMake Makefiles" -DCMAKE_CL_64:BOOL=on -DCMAKE_INSTALL_PREFIX=C:\local\sundials-2.6.2-x64-install

However, when I inspect the CMakeCache.txt file (attached), it still shows the target architecture as being x86.  I've also inspected the .lib files generated using the VisStudio dumpbin tool.  This tool lets me inspect the binary library files and I can determine if the build is, in fact, x86 or x64.  See image below... it's x86.  So, this may be an issue in linking to an x64 compile of Cantera.



Second potential problem: 
As for the installation location of everything, I'm installing Boost, Sundials, and Cantera to "C:\local".  I've unzipped the Cantera 2.2.1 source to: "C:\local\cantera-2.2.1" and created a build directory "C:\local\cantera-2.2.1-build".  Here's the contents of my cantera.conf file.

msvc_version = '14.0'
target_arch = 'x86_64'
prefix = 'C:\\local\\cantera-2.2.1-build'
f90_interface = 'n'
use_sundials = 'y'
sundials_include = 'C:\\local\\sundials-2.6.2-x64-install\\include'
sundials_libdir = 'C:\\local\\sundials-2.6.2-x64-install\\lib'
env_vars = 'all'
build_thread_safe = True
boost_inc_dir = 'C:\\local\\boost_1_61_0'
boost_lib_dir = 'C:\\local\\boost_1_61_0\\lib64-msvc-14.0'

From the "C:\local\cantera-2.2.1" directory, I run "scons build".  I've made sure to change my python path and python scripts paths to the 64 bit installation locations so that it should be grabbing the appropriate SCons installation.

SCons gets part of the way though the build process before failing.  Here's where it stops:


When I go into the "C:\local\cantera-2.2.1\build\lib" directory, I can see where it stopped:




The error messages appear to be Boost-related.  However, I know that I've got the precompiled-libraries for Boost for MSVC-14 (i.e. Visual Studio 2015).
CMakeCache.txt

Ray Speth

unread,
Jul 19, 2016, 4:37:12 PM7/19/16
to Cantera Users' Group
Nicholas,

The valid options for target_arch are 'x86' and 'amd64'. The value you specified ('x86_64') is being ignored, so you are getting an x86 build.

You certainly also need to fix the 32-bit Sundials build. You should not need to manually edit any of the CMake output -- specifying the correct compiler should be part of the options when you first configure the project.

Regards,
Ray

P.S. Please copy text from the command window rather than posting screenshots: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_dos_copy.mspx?mfr=true

Nicholas Mueschke

unread,
Jul 19, 2016, 4:39:18 PM7/19/16
to Cantera Users' Group
One quick update.  I can compile Cantera in 32 bit mode just fine (sort of).

Fist, I changed the cantera.conf file to this:
msvc_version = '14.0'
target_arch = 'x86'
prefix = 'C:\\local\\cantera-2.2.1-build32'
f90_interface = 'n'
use_sundials = 'y'
sundials_include = 'C:\\local\\sundials-2.6.2-x86-install\\include'
sundials_libdir = 'C:\\local\\sundials-2.6.2-x86-install\\lib'
env_vars = 'all'
build_thread_safe = True
boost_inc_dir = 'C:\\local\\boost_1_61_0'
boost_lib_dir = 'C:\\local\\boost_1_61_0\\lib32-msvc-14.0'

Here's the compilation result:


When i run the tests, I get some failed tests, one doesn't run because it can't find "sundials_cvodes.dll", and then eventually one test won't compile.



That may not matter thought.  I ran the "SCons install" command and everything appears to be installed in a 32-build folder I created.



This 32 bit compile and install used the pre-compiled 32 bit Boost libraries (MSVC-14)... i.e. from the same place I got the 64 bit MSVC-14 Boost libraries.


I hope some of this information helps.



On Tuesday, July 19, 2016 at 11:52:52 AM UTC-5, Nicholas Mueschke wrote:

Bryan W. Weber

unread,
Jul 19, 2016, 4:42:20 PM7/19/16
to Cantera Users' Group
Nicholas,

You also need to be using the x64 Developer Console (I forget exactly what its called, but its clearly for x64) - its a separate shortcut in the Start Menu. IIRC, the default is for 32-bit compilers to be used. Many apologies for not clarifying that in my post...

Best,
Bryan

Ray Speth

unread,
Jul 19, 2016, 4:53:56 PM7/19/16
to Cantera Users' Group
Nicholas,

The test failure related to "_TWO_DIGIT_EXPONENT" is to be expected. Cantera 2.2 is only fully compatible with Visual Studio 2013, but I think the removal of this function, which is used only in the tests, is the only actual compatibility issue.

If you built shared libraries for Sundials and are trying to use those, then they need to be available on your PATH in order for Cantera to find them. I usually find it easier to just build the static Sundials libraries for this reason.

Regards,
Ray

Nicholas Mueschke

unread,
Jul 19, 2016, 4:55:56 PM7/19/16
to Cantera Users' Group
To Ray and Brian... thank you so much for the help.

Brian, I was not aware of the x64-specific command prompt.  Thanks for pointing that out.

I'll modify my cantera.conf file to use "amd64" for the target arch and move to the 64 bit command window and see what happens.

Reply all
Reply to author
Forward
0 new messages