Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build Cantera 2.3.0 with fmt 4.0.0 #470

Closed
adamjstewart opened this issue Aug 3, 2017 · 13 comments
Closed

Unable to build Cantera 2.3.0 with fmt 4.0.0 #470

adamjstewart opened this issue Aug 3, 2017 · 13 comments

Comments

@adamjstewart
Copy link

Cantera version

2.3.0

Operating System

CentOS 7, GCC 7.1.0

Python/MATLAB version

Python 2.7.13, no MATLAB

Expected Behavior

I'm trying to build the latest version of Cantera, but it crashes with some fmt-related error messages

Actual Behavior

In file included from src/clib/clib_utils.h:11:0,
                 from src/fortran/fctxml.cpp:9:
include/cantera/base/global.h: In function ‘void Cantera::writelogf(const char*, const Args& ...)’:
include/cantera/base/global.h:201:26: error: ‘sprintf’ is not a member of ‘fmt’
     writelog_direct(fmt::sprintf(fmt, args...));
                          ^~~~~~~
include/cantera/base/global.h:201:26: note: suggested alternative: ‘print’
     writelog_direct(fmt::sprintf(fmt, args...));
                          ^~~~~~~
                          print
/blues/gpfs/home/ajstewart/spack/lib/spack/env/gcc/gfortran -o build/src/fortran/cantera_funcs.o -c -O3 -Ibuild/src/fortran -Isrc/fortran -Isrc/fortran -Jbuild/src/fortran src/fortran/cantera_funcs.f90
Compiling /tmp/ajstewart/spack-stage/spack-stage-6FEzO7/cantera-2.3.0/interfaces/cython/cantera/_cantera.pyx because it changed.
[1/1] Cythonizing /tmp/ajstewart/spack-stage/spack-stage-6FEzO7/cantera-2.3.0/interfaces/cython/cantera/_cantera.pyx
In file included from include/cantera/thermo/SpeciesThermoInterpType.h:18:0,
                 from include/cantera/thermo/MultiSpeciesThermo.h:13,
                 from include/cantera/thermo/ThermoPhase.h:15,
                 from include/cantera/kinetics/Kinetics.h:14,
                 from include/cantera/kinetics/KineticsFactory.h:11,
                 from src/fortran/fct.cpp:14:
include/cantera/base/global.h: In function ‘void Cantera::writelogf(const char*, const Args& ...)’:
include/cantera/base/global.h:201:26: error: ‘sprintf’ is not a member of ‘fmt’
     writelog_direct(fmt::sprintf(fmt, args...));
                          ^~~~~~~
include/cantera/base/global.h:201:26: note: suggested alternative: ‘print’
     writelog_direct(fmt::sprintf(fmt, args...));
                          ^~~~~~~
                          print
/blues/gpfs/home/ajstewart/spack/lib/spack/env/gcc/gfortran -o build/src/fortran/cantera.o -c -O3 -Ibuild/src/fortran -Isrc/fortran -Isrc/fortran -Jbuild/src/fortran src/fortran/cantera.f90
scons: *** [build/src/fortran/fctxml.o] Error 1
scons: *** [build/src/fortran/fct.o] Error 1
scons: building terminated because of errors.

Steps to reproduce

I'm attempting to add this version of Cantera to the Spack package manager in spack/spack#4936. You can use Spack to build everything, or build it by hand.

@bryanwweber
Copy link
Member

Thanks for the report! @speth noted that there have been changes to fmt since the 3.0.1 release that we bundle (https://groups.google.com/d/msg/cantera-users/vIE7kqPYQEY/SMuogmHBBAAJ). At the moment, the only solution is to use that version of fmt (3.0.1), either installed on your system, or the one bundled as submodule in Cantera. As @speth noted in that Google Group post, updating to handle both versions of the fmt library is going to take some doing.

@adamjstewart
Copy link
Author

Thanks @bryanwweber! I tried 3.0.2 and that seems to work. I imagine anything from the 3.0.X build cycle is API-compatible. I've updated the Spack Cantera package with the latest release. Everything should be good to go now.

@bryanwweber
Copy link
Member

Awesome, good to know @adamjstewart. I'm going to re-open this issue as a reminder that we have to update for fmt 4.x at some point.

@bryanwweber bryanwweber reopened this Aug 3, 2017
@JPR984
Copy link

JPR984 commented Aug 4, 2017

I have run into the same error on my Mac(Sierra) I have uninstalled fmt 4.0.0 but I could use some help installing fmt 3.0.2.

@adamjstewart
Copy link
Author

@JPR984 You can wait until spack/spack#4936 is merged and run spack install cantera (which will build fmt for you) or run spack install fmt@3.0.2. Alternatively, it isn't hard to build fmt from source:

curl -O https://github.com/fmtlib/fmt/releases/download/3.0.2/fmt-3.0.2.zip
unzip fmt-3.0.2.zip
cd fmt-3.0.2
mkdir build
cd build
cmake ..
make
sudo make install

You may want to change the installation prefix, but that's up to you.

@JPR984
Copy link

JPR984 commented Aug 4, 2017

@adamjstewart perfect thank you It installed fmt 3.0.2 and have Cantera installing as I type and it so far seems to be working. I appreciate the help!

@charlesreid1
Copy link

charlesreid1 commented Aug 14, 2017

Running into this problem on a Mac using Homebrew to install Cantera. No formulas exist for fmt versions < 4.0. Any suggestions that use Homebrew and not spack or from source?

$ brew info fmt
fmt: stable 4.0.0 (bottled)
Open-source formatting library for C++
https://fmtlib.github.io/
/usr/local/Cellar/fmt/4.0.0 (20 files, 418.9KB) *
  Poured from bottle on 2017-08-13 at 17:42:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/fmt.rb
==> Dependencies
Build: cmake ✘

$ brew switch fmt 3.0.2
Error: fmt does not have a version "3.0.2" in the Cellar.
Versions available: 4.0.0

$ brew switch fmt 3.0.0
Error: fmt does not have a version "3.0.0" in the Cellar.
Versions available: 4.0.0

@charlesreid1
Copy link

charlesreid1 commented Aug 14, 2017

The following method is a complete and utter hack, but it works (Mac OS X Sierra 10.12.5)...

Modify the contents of the fmt Formula to use 3.0.2 instead of 4.0.0:

$ cat /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/fmt.rb
class Fmt < Formula
  desc "Open-source formatting library for C++"
  homepage "https://fmtlib.github.io/"
  url "https://github.com/fmtlib/fmt/releases/download/3.0.2/fmt-3.0.2.zip"
  sha256 "51407b62a202b29d1a9c0eb5ecd4095d30031aea65407c42c25cb10cb5c59ad4"

  bottle do
    cellar :any_skip_relocation
    sha256 "4b1ef0852ab31be3d350262d4a002a3a0de4d99191454968607b629d6728a034" => :el_capitan
    sha256 "e8a3d6249d417f6a56e012b7327239ba5ab1993264260a612b5108e017cb5c66" => :yosemite
    sha256 "eaf14af839288acc850ac113ccd9116cb51e1366344d4c2e17d8b1070bd29aa6" => :mavericks
  end

  depends_on "cmake" => :build

  def install
    system "cmake", ".", *std_cmake_args
    system "make", "install"
  end

  test do
    (testpath/"test.cpp").write <<-EOS.undent
      #include <iostream>
      #include <string>
      #include <fmt/format.h>
      int main()
      {
        std::string str = fmt::format("The answer is {}", 42);
        std::cout << str;
        return 0;
      }
    EOS

    system ENV.cxx, "test.cpp", "-o", "test",
                  "-I#{include}",
                  "-L#{lib}",
                  "-lfmt"
    assert_equal "The answer is 42", shell_output("./test")
  end
end

Now unlink the old fmt, and install the new fmt:

$ brew unlink fmt; brew install fmt
==> Downloading https://github.com/fmtlib/fmt/releases/download/3.0.2/fmt-3.0.2.zip
Already downloaded: /Users/charles/Library/Caches/Homebrew/fmt-3.0.2.zip
==> cmake . -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/fmt/3.0.2 -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBO
==> make install
🍺  /usr/local/Cellar/fmt/3.0.2: 16 files, 363.8KB, built in 45 seconds

Now Cantera should build successfully:

$ brew install cantera
==> Installing cantera from homebrew/science
==> Downloading https://homebrew.bintray.com/bottles-science/cantera-2.3.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cantera-2.3.0.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/cantera/2.3.0: 590 files, 197.8MB

Voila! It works:

$ python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cantera
>>>

In the meantime I will wait for Cantera to be updated to use fmt 4.0.0 (and cross my fingers and hope that nothing else in Homebrew used fmt 4.0.0).

@speth
Copy link
Member

speth commented Aug 15, 2017

This should be fixed in ea69a01. I have also cherry-picked this onto the 2.3 branch, so it will be part of any eventual maintenance releases as well.

For Homebrew, you should now be able to install by adding the --HEAD argument (which will install the current development version instead of 2.3.0).

@speth speth closed this as completed Aug 15, 2017
@charlesreid1
Copy link

Thanks Ray! After restoring the fmt formula, adding --HEAD worked out great.

$ brew install --HEAD cantera
[...]
🍺  /usr/local/Cellar/cantera/HEAD-ea69a01: 602 files, 191.4MB, built in 33 minutes 16 seconds

@micromad
Copy link

micromad commented Sep 7, 2017

To compile Cantera 2.3 with fmt-4, you just need to modify the file include/cantera/base/fmt.h by adding the line:
#include "cantera/ext/fmt/printf.h"
after the 'else' and copy the printf.h from the include directory of fmt to the include/cantera/ext/fmt directory.

@band-a-prend
Copy link
Contributor

band-a-prend commented Mar 4, 2018

I tried to compile cantera 2.3.0 with system fmt 4.1.0 in Gentoo linux and got the same error.
I just add line:

#include <fmt/printf.h>

to file <cantera_source_dir>/include/cantera/base/global.h
and after that cantera build successfully.

or to file <cantera_source_dir>/include/cantera/base/fmt.h add #include "fmt/printf.h"
to the section '#if CT_USE_SYSTEM_FMT'

But it breaks building if <=fmt-3.0.2 is used.

update:
I looked into fmt 4.0.0 changelog and there is mentioned that
Moved fmt::printf() to new printf.h header
early this function was placed into format.h

Also the FMT documentation saying:
The header fmt/printf.h provides printf-like formatting functionality.

update2:
This solution also was already discussed/found early in:
https://groups.google.com/forum/#!msg/cantera-users/vIE7kqPYQEY/34z1G0W8BAAJ

@goru14qe
Copy link

I tried installing cantera 2.6.0 with just:
git clone --recursive https://github.com/Cantera/cantera.git
cd cantera
git checkout 2.6
scons build prefix=path/.../cantera f90_interface=n python_package=none sundials_include=path/../include sundials_libdir=path/../lib64 boost_inc_dir=path/../include

For the longest time it gave me the error for fmt.os.

All the suggestions mentioned here were either for older versions of fmt and cantera or did not work.

So finally according to me the error and solution.
While git checkout 2.6 , it does not checkout to the mentioned commit number that was supposed to be compatible. Rather it just takes either the latest version, oor random version. Therefore if you go to fmt git: https://github.com/fmtlib/fmt/tree/19bd751020a1f3c3363b2eb67a039852f139a8d3 and search for commit [19bd751] or the commit mentioned on the git of cantera/ext of the version you want. and download and replace the version manually. It goes for all the dependencies. For this particular case of cantera 2.6.0, the fmt of v6.2.1 https://github.com/fmtlib/fmt/releases/tag/6.2.1 worked.

Hope it helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants