Visual Studio 2010 includes / linker settings C++

985 views
Skip to first unread message

Aadinath

unread,
Jan 28, 2014, 12:00:34 PM1/28/14
to canter...@googlegroups.com
Hello everyone,

As part of a larger project involving a generic combustion model (written primarily in C++), I have been trying to use the C++ interface for Cantera via Visual Studio 2010. I installed Cantera as per the instructions on the wiki (https://code.google.com/p/cantera/wiki/WindowsInstallation)- I am using Windows 7 (64-bit), Visual Studio Professional (32-bit) and Windows SDK 7 (for the required 64-bit compilers). The Python test is a success.

I am having trouble instructing the compiler and linker to pick up the correct directories because I do not understand how they work and what they do. To be honest, I have never actually included any dependency libraries (other than .h files written on my own for the code and what the IDE points to by default) so my apologies for the naivete.

The Cantera installation was done under ".../Program Files/Cantera".

Visual  Studio settings as follows:
Configuration: Debug
Platform : x64

Under Project>>Properties I navigate to the "Configuration Properties" drop down list. 
Further under "VC++ Directories" I find 
Executable Directories 
Include Directories
Reference Directories
Library Directories
Source Directories
Exclude Directories

and under "Linker>>General" I find:
Additional Library Directories

I had a look at Cantera.mak in order to try and figure out what directories are to be included where, but the few combinations I tried all gave multiple compile and link time errors. 

Can someone help me out with the includes and library directories?

Thanks  in advance,

Aadi

PS: I need to duplicate this environment at work, where I have no admin rights. So I have built many of the package dependencies from source and tried building Cantera through Cygwin (without success). I will update/follow up this post if that works out.

Nick Curtis

unread,
Jan 28, 2014, 2:49:14 PM1/28/14
to canter...@googlegroups.com
Hi Aadi,
These are my VS2012 settings (they should largely be the same):

Under Configuration Properties -> C++ -> General -> Additional Include Directories:
....\Program Files\Cantera\include;...\Program Files\Sundials\include;...\Program Files\Boost\boost\

Under Configuration Properties -> Linker -> General -> Additional Library Directories:
...\Program Files\Boost\lib\;...Program Files\Cantera\lib;...\Program Files\Sundials\lib

Under Configuration Properties -> Linker -> Additional Dependencies you need to add to following:
cantera.lib;sundials_cvodes.lib;sundials_nvecserial.lib

Before kernel32.lib

*note that you may or may not need the Sundials and Boost includes depending on how you built Cantera (i.e. w/ Sundials and Boost thread support)

On *Nix we've had the best success installing to the .local directory of each user's home (thus no global cantera install)
I recommend visiting Bryan Weber's excellent website, which details our build on an Ubuntu 12.04 server

Nick

Nick Curtis

unread,
Jan 28, 2014, 3:02:31 PM1/28/14
to canter...@googlegroups.com
Oh, also... the Boost\lib folder may not be named that way on your system.  It depends how your got Boost installed, where you got it from etc.

Basically it's the folder with a bunch of library files e.g. something like: boost_system-vc110-1_54.lib inside.

Aadinath

unread,
Jan 29, 2014, 5:03:42 AM1/29/14
to canter...@googlegroups.com
Thanks Nick!

Your heads-up regarding the Boost libraries was particularly useful. I used the prebuilt binaries for Boost (boost_1_55_0-msvc-10.0-64.exe), so I'm assuming 'C:/local/boost_1_55_0/lib64-msvc-10.0/' is the required path at my end.

Perhaps I wasn't entirely clear, but my work environment also has (and requires) Win 7 and MSVC. Here is my current work-flow for installing Cantera (without admin rights) on Win 7 (64-bit) with Visual Studio 2010 (64-bit) already installed. This workflow is based on instructions from http://cantera.github.io/docs/sphinx/html/compiling.html 

1. Install Cygwin (64-bit) on Win 7 
2. Under Cygwin, install python
3. Download the sundials source (http://computation.llnl.gov/casc/sundials/download/download.html)  and build from Cygwin (./configure && make && make install).  This builds sundials (2.5.0) using g++ taken from Cygwin. Now I'm not certain if I can use libraries/includes built for sundials using g++ later in MSVC. I would have liked to have built Sundials with the 64-bit MSVC compiler but couldn't call it from Cygwin (bash: cl not found). This https://stackoverflow.com/questions/366928/invoking-cl-exe-msvc-compiler-in-cygwin-shell thread talks about the workaround, but all of the alternatives mentioned with editing the .bat files must be discarded since their execution requires elevation. Setting environment variables directly by running the MSVC command prompt also fails. My question here is: Does building sundials with --enable-shared flag circumvent this compiler issue? I proceed nevertheless (with g++ as the compiler on Cygwin) and succeed in building sundials. [config.log for sundials attached]
4. Download the pre-build binaries for Boost. The resulting install (requires no admin rights) extracts in addition to the specific libraries (in my case the MSVC folder), the usual boost directories as well. As I understand, Boost doesn't have to be built for cantera to work. Again, since I have no access to cl from within Cygwin, I feed only the usual boost paths to cantera.conf. Passing msvc_version, toolchain, target_arch is of no use either.
5. Scons can be installed under Cygwin, but I choose to use the Production version (2.3.0) of the scons-local package (http://www.scons.org/download.php). There are 64-bit issues for scons with python, hence this solution. Extract this package- note that scons.py is in the top level directory (in my case, this is called SCons_extract).
6. Download and extract the cantera source and place it in the Cygwin directory. From inside the cantera directory, call scons.py through python ($ python ../SCons_extract/scons.py install). This assumes that the cantera.conf [attached] resides in the cantera directory.

It goes downhill from here- please find the cantera build results in cantera_build_log [attached]. I am trying to first solve the problem of invoking cl in Cygwin and then rebuilding sundials. 

In the meanwhile, any suggestions are welcome and appreciated.

Best,

Aadi
cantera.conf
config.log
cantera_build_log.txt

Nick Curtis

unread,
Jan 29, 2014, 10:23:58 AM1/29/14
to canter...@googlegroups.com
Hi Aadi,

'C:/local/boost_1_55_0/lib64-msvc-10.0/' looks like the right path

Ahhh, that makes more sense.
So basically mixing compilers is bad idea.  It can be done, but generally it's not recommended.

Here's my general install order: 
1.  Install python directly (not under cygwin) - I use Anaconda (http://continuum.io/downloads) as it comes packaged with matplotlib/numpy.  You can also use the 64 bit install directly from python.org, and use Christopher Gothke's page (http://www.lfd.uci.edu/~gohlke/pythonlibs/) to get all your libraries (i.e. numpy)

2.  Download Sundials src (2.4.0 or 2.5.0)
3.  Download CMake GUI (http://www.cmake.org/)
4.  Use CMake to build Sundials using Visual Studio as your compiler.  This (http://sundials.wikidot.com/installation-cmake-vs) page is a bit old, but has very good instructions on how to do so.  You can generally substitute VS2010 for VS2008 in those instructions.  You may or may not need to change the idasRoberts_FSA_dns settings to compile as C++ (I think it was resolved in 2.5.0)
5.  Download Pre-Compiled Boost from (http://boost.teeks99.com/).  Extract to whatever folder you want.  (It seems like you got this step)
6.  Download SCons source. 
7.  Open up the Visual Studio command line (it's nice and helpful, it sets all your paths etc for you)
8.  Navigate to the SCons directory
9.  python setup.py install (Make sure you added your Python install to your path, IIRC, Anaconda does this for you)
10.  Download Cantera src and extract
11.  You're almost there, now is mostly build settings in your cantera.conf file. 
My cantera.conf looks like this:

msvc_version = '10' #9 for 2008, 10 for 2010, 11 for 2012
prefix = 'C:\\Program Files\\Cantera' #or wherever
f90_interface = 'n'
use_sundials = 'y'
sundials_include = 'C:\\Program Files\\Path\\To\\Sundials\\include'
sundials_libdir = 'C:\\Program Files\\Path\\To\\Sundials\\lib'
env_vars = 'all' #important, lets SCons get all your path variables etc.
build_thread_safe = True #optional, but you have the boost libraries so why not!
boost_inc_dir = 'C:\\Program Files\\Path\\To\\Boost\\boost_1_55_0'
boost_lib_dir = 'C:\\Program Files\\Path\\To\\Boost\\boost_1_55_0\\lib64-msvc-10.0'

12.  in the VS Command prompt, cd to the Cantera/src directory (where your .conf lives), now you should be able to call python scons [build/test/install] (each one in series)
13.  If you run into a problem building the python interface with an error something like "missing vcvarsall.bat"

This is because Python is built with VS2008, and by default it looks for VS2008's version of vcvarsall.bat.
Three solutions:
1.  If you have VS2008, use the VS2008 command prompt to build cantera
2.  If you don't have VS2008, you can create an environment variable "VS90COMNTOOLS", and give it exactly the same path that the pre-existant environment variable "VS100COMNTOOLS" has.  This redirects python to the 2010 files.  This is not guaranteed to be a perfect fix, but I have not noticed many issues with it.
3.  Get the VS2008 x64 windows SDK (http://www.microsoft.com/en-us/download/details.aspx?id=3138) and figure out how to use it (you probably just need to create that environment variable, but I'm not 100% on this)

That should do it.

Now you can complicate this process further if you have a license of Intel's MKL library.  Basically you need to figure out how to stick MKL into CMake, and then set the appropriate options in the cantera.conf.  I would not recommend anything other than MKL on Windows however.  Speaking from personal experience, MKL is the only BLAS/LAPACK library on Windows that I've found that does not have to be compiled under Cygwin (which as you likely know, invites a whole world of fun)

Best,
Nick

Nick Curtis

unread,
Jan 29, 2014, 10:27:46 AM1/29/14
to canter...@googlegroups.com
I wish Google groups would let me edit posts
On Windows it's just scons and not python scons
Message has been deleted

Aadinath

unread,
Jan 29, 2014, 7:29:31 PM1/29/14
to canter...@googlegroups.com
Nick,

I'm not sure with what intuition you meant "almost there" at point 11, but that's where its stopped :-)

I am trying to build cantera from source through the Visual Studio command prompt (running as administrator), and end up with the error:
ERROR: Unable to find Sundials headers and / or libraries

The build output from cmd [catera_build_log,txt] as well as the config.log file are attached.

Since many of the dependencies are being built from source, let me also ask this: should I be also building BLAS/LAPACK into sundials/cantera? The application I am working on (not just the cantera part- I mean the project as a whole) is intended to be parallelized eventually. Thus I am also curious if MPI specific build instructions must be incorporated right from the beginning in the dependencies.

Thanks and cheers

Aadi


On Wednesday, January 29, 2014 7:36:18 PM UTC+1, Aadinath wrote:
Thanks a ton, Nick.

Let me give the workflow you proposed a try- I will revert whatever be the result.

Best,

Aadinath
config.log
cantera_build_log.txt

Aadinath

unread,
Jan 29, 2014, 7:38:25 PM1/29/14
to canter...@googlegroups.com
Ironic +1 for "I wish Google groups would let me edit posts" , I forgot the cantera.conf file. Attached here.
cantera.conf

Nick Curtis

unread,
Jan 30, 2014, 10:06:01 AM1/30/14
to canter...@googlegroups.com
Hi Aadi,
Can you make sure that following folders exist in
'C:\\Program Files\\sundials\\include\\'

cvode, cvodes, ida, idas, kinsol, nvector, sundials


And in:

'C:\\Program Files\\sundials\\lib\\'

you should have the following libraries:

sundials_cvode.lib
sundials_cvodes.lib
sundials_ida.lib
sundials_idas.lib
sundials_kinsol.lib
sundials_nvector.lib

Your build appears to be configured correctly... I have run into occasional issues with installing Sundials w/ CMake and VS.
Nothing insurmountable, just that sometimes the files don't actually get installed (make sure you set your install path to
C:\\Program Files\\sundials\\ in CMake!)

One thing to try is to completely rebuild Sundials.
Open CMake, navigate to a different folder, navigate back to sundials (to clear the cache)
Regenerate your solution file.
Open in VS
Clean Solution
Build the "All Build" project
Build the "Install" project

Also, you may want to switch to a Release build of Sundials (for speed reasons)

Ray Speth

unread,
Jan 30, 2014, 11:11:06 AM1/30/14
to canter...@googlegroups.com
Aadinath,

The relevant bit of config.log is the following in the test for the sundials_cvodes library:

link /nologo /DEBUG /OUT:.sconf_temp\conftest_6.exe "/LIBPATH:C:\Program Files\boost_1_55_0\lib64-msvc-10.0" "/LIBPATH:C:\Program Files\sundials\lib" sundials_cvodes.lib .sconf_temp\conftest_6.obj
conftest_6.obj : error LNK2019: unresolved external symbol _CVodeCreate referenced in function _main
.sconf_temp\conftest_6.exe : fatal error LNK1120: 1 unresolved externals

What this says is that it found the library file (otherwise you would have gotten an error about a missing file), but that it does not contain the required symbol. The only thing I can think of that would cause this is if you built a 32-bit sundials and are building a 64-bit Cantera, or vice versa. You can double check which architecture you built Sundials for in the VS project. For Cantera, edit SConstruct and find the line (approx 141):

    env['OS_BITS'] = int(platform.architecture()[0][:2])

and after that, add:

    print 'OS_BITS =', env['OS_BITS']

And see what that prints out when you run 'scons build'.

Regards,
Ray

Aadinath

unread,
Feb 5, 2014, 7:59:59 AM2/5/14
to canter...@googlegroups.com
Hello Ray/Nick,

It took some time for me to figure be able to go past that last error- what finally worked was first uninstalling Visual Studio Professional and then installing the Express version and SDK 7.1 instead. Further, I thought the "bitness" conflict that Ray spoke about came from also the old Visual Studio 64-bit compiler/linker- thus I decided to run Release builds in win32 configuration for everything. Of course, I am using Anaconda 32-bit (Python->scons) and subsequently building sundials also as 32-bit from Visual Studio.

scons build now goes past the initial phase the resulting config.log is attached]:
OS_BITS = 32
....
(....other compilation output)
....
Generating include\cantera\base\config.h with the following settings:
    CANTERA_VERSION "2.1.0"
    FTN_TRAILING_UNDERSCORE         1
    HAS_NUMPY 1
    HAS_SUNDIALS    1
    LAPACK_FTN_STRING_LEN_AT_END 1
    LAPACK_FTN_TRAILING_UNDERSCORE 1
    LAPACK_NAMES_LOWERCASE 1
    RXNPATH_FONT "Helvetica"
    SUNDIALS_VERSION 24
    THREAD_SAFE_CANTERA 1
    USE_BOOST_MATH 1
...
...
 and exits trying to build IDA_Solver.cpp. The last few lines from the Visual Studio command prompt are attached in [scons_build_log_last.txt].

Any suggestions on how to proceed?

Thanks and best regards,

Aadi
config.log
cantera.conf
scons_build_log_last.txt

Aadinath

unread,
Feb 5, 2014, 10:52:43 AM2/5/14
to canter...@googlegroups.com
UPDATE:

Successfully built and installed. A quick C++ program also runs fine.

I changed the following from my earlier post:

1. Rebuild Sundials (2.4.0) and not 2.5.0 [figured sundials was the problem since IDA_solver.cpp was the roadblock]
2. Encountered vsvarsall.bat error. Setting environment variable VS90COMNTOOLS to point to the same path as VS100COMNTOOLS was successful.  (Nick had rightly predicted both)

Thanks a ton, Nick and Ray. My Cantera journey begins =)

Cheers
Message has been deleted

John wang

unread,
Apr 6, 2014, 8:07:03 AM4/6/14
to canter...@googlegroups.com
Sundials (2.5.0) is wrongly set as 2.4.0 in its CMakeList file. see my post here:

Reply all
Reply to author
Forward
0 new messages