Compilation NameError

185 views
Skip to first unread message

David Schmider

unread,
Jun 9, 2021, 12:09:20 PM6/9/21
to Cantera Users' Group
Hi,

my name is David Schmider and I'm a PhD student at University of Applied Sciences in Offenburg. Currently I'm working on an extension of the BinarySolutionTabulatedThermo class to implement stoichiometry dependent partial molar volumes. 
Since we coupled Cantera to an in-house code for battery simulation, I started implementing the changes within the latest working setup, which used Cantera 2.4. There everything works fine. Before starting a pull request, I wanted to test the extensions with the most recent version of the main branch of Cantera, but after checking out the main branch I get compilation NameErrors:

NameError: name 'Dict' is not defined:
  File "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\workspace\Cantera\SConstruct", line 1721:
    SConscript('build/src/fortran/SConscript')
  File "d:\hso\codes\denis\ide_mcdenis_64\python395\lib\site-packages\SCons\Script\SConscript.py", line 654:
    return method(*args, **kw)
  File "d:\hso\codes\denis\ide_mcdenis_64\python395\lib\site-packages\SCons\Script\SConscript.py", line 591:
    return _SConscript(self.fs, *files, **subst_kw)
  File "d:\hso\codes\denis\ide_mcdenis_64\python395\lib\site-packages\SCons\Script\SConscript.py", line 280:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\workspace\Cantera\build\src\fortran\SConscript", line 38:
    SPAWN=get_spawn(localenv),
  File "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\workspace\Cantera\site_scons\buildutils.py", line 841:
    def our_spawn(sh: str, escape: str, cmd: str, args: str, environ: Dict[str, str]):

My first guess was, that is has something to do with the type annotations in the function definition of our_spawn. As it seems to be a forward reference, I put the Dict[str, str] in quotes  "Dict[str, str]", resulting in a different NameError during compilation:

scons: *** [interfaces\python_minimal\dummy] NameError : name 'normpath' is not defined
Traceback (most recent call last):
  File "d:\hso\codes\denis\ide_mcdenis_64\python395\lib\site-packages\SCons\Action.py", line 1280, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\workspace\Cantera\interfaces\python_minimal\SConscript", line 63, in find_module_dir
    global_env['python_module_loc'] = normpath(filename)
NameError: name 'normpath' is not defined

Since forward referencing in type annotations has become possible without using quotes in Python 3.7 I also tried upgrading the Python version used in our Eclipse IDE from 3.6.8 to 3.9.5 but that still could not resolve the NameErrors.
I tried to track down where the compilation problems started and it seems that the changes made in commit edf5e4cc cause the problems. At least I can compile all versions of Cantera before that commit without NameErrors. Compiling edf5e4cc results in:

NameError: name 'quoted' is not defined:
  File "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\workspace\Cantera\SConstruct", line 1211:
    env['python_cmd_esc'] = quoted(env['python_cmd'])

I'm using scons and Mingw64 for the build process.
Any help on this will be much appreciated.

Best regards,
David

Bryan Weber

unread,
Jun 9, 2021, 1:42:47 PM6/9/21
to Cantera Users' Group
Hi David,

Thanks for reporting this! Both those problems were introduced in pull request #1012 by me :-) I've pushed a branch that hopefully fixes these problems here: https://github.com/Cantera/cantera/pull/1052 Can you try using that branch and see if the problems are resolved?

Best,
Bryan

David Schmider

unread,
Jun 10, 2021, 7:17:49 AM6/10/21
to Cantera Users' Group
Hi Bryan,

thanks for the quick reply. Compilation works with the branch you linked but only when I use a newer version of SCons (4.1.0.post1 in this case). When I compile with the previously used SCons version 3.1.1, I get the following error, indicating problems with the Fortran compiler:

f90 -o build\src\fortran\fctxml_interface.o -c -O3 -Ibuild\src\fortran -Isrc\fortran -Isrc\fortran -Jbuild\src\fortran src\fortran\fctxml_interface.f90
f90 -o build\src\fortran\fct_interface.o -c -O3 -Ibuild\src\fortran -Isrc\fortran -Isrc\fortran -Jbuild\src\fortran src\fortran\fct_interface.f90
Der Befehl "f90" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Der Befehl "f90" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
cd interfaces/python_minimal && "D:\HSO\Codes\DENIS\IDE_MCDENIS_64\Python368\python.exe" setup.py build --build-lib=../../build/python
running build
running build_py
copying cantera\__init__.py -> ../../build/python\cantera
scons: *** [build\src\fortran\fctxml_interface.o] Error 1
scons: *** [build\src\fortran\fct_interface.o] Error 1

I don't know if this is some specific error for my build setup but since it works with a newer version of SCons I'm fine. 
Nevertheless I thought I'd mention it, as in the Cantera Dependencies it says "Cantera 2.4.0 and up must use SCons >= 3.0.0" so actually it should be also working with 3.1.1.

Regarding the pull request: should I base my changes on your branch then or wait for these changes to be included in the main branch and start my pull request based on that?

Again, thank you very much for your help.

Best regards,
David

Ingmar Schoegl

unread,
Jun 10, 2021, 11:41:35 AM6/10/21
to Cantera Users' Group
Interesting. At the face of it the error


"Der Befehl "f90" ist entweder falsch geschrieben oder konnte nicht gefunden werden."

means that "f90" isn't found by the system ('command is either mistyped or not found'). It's funny that this appears to be dependent on the SCons version. Requiring a newer SCons may be an easy fix, but may mask an underlying issue.

Bryan Weber

unread,
Jun 10, 2021, 3:11:39 PM6/10/21
to Cantera Users' Group
Thanks for the translation Ingmar. It's likely that this is related to SCons support for MinGW, and there's not a whole lot Cantera can do about it (other than perhaps catch the version in SConstruct, but I don't really want to go down that rabbit hole of figuring out which versions are supported when). For instance, SCons generally has to release a new version when a new VC++ is released due to the way that they try to find compilers. Another example is that SCons can't find VC 14.1 if 14.2 is installed, again due to something internal in SCons (https://github.com/SCons/scons/issues/3664).

For what it's worth, another option (if you don't use Fortran) is to disable compiling that interface, f90_interface=n in cantera.conf.

Anyhow, thanks for the error report David! Yes, you can base your changes on my branch, and then rebase your changes onto the main branch once my PR is merged.

Best,
Bryan

Ray Speth

unread,
Jun 10, 2021, 3:18:23 PM6/10/21
to Cantera Users' Group

Hi David,

Could you post the full log output of the scons build command after having first run scons clean? What confuses me about this is why it’s trying to build the Fortran interface. Normally, the first step should be to check for a working Fortran compiler, and if that isn’t found, it should either disable compilation of the Fortran module (if the f90_interface option wasn’t specified) or stop with an error (if the f90_interface option was set to y).

Regards,
Ray

David Schmider

unread,
Jun 11, 2021, 7:16:54 AM6/11/21
to Cantera Users' Group
Hi all,

@Bryan: Indeed, I actually don't need the Fortran Interface, so disabling that with f90_interface=n also works. But previously that parameter was always left at 'default', so per default, SCons found the 'gfortran' compiler in our IDE and built the Fortran Interface (as you can also see in the SCons build log Python368_Scons311_Cantera2.5.0a4.txt).

@Ray: When I build the branch of Bryan with SCons version 3.1.1 it shows in the log, that a suitable Fortran compiler 'gfortran' is found and therefore tries to build the Fortran Interface. The compilation fails when SCons tries to invoke f90 commands (see Python368_Scons311.txt). I wonder why this happens because it actually found the correct 'gfortran' compiler. This even happens when I specify the path to gfortran.exe with the FORTRAN=... configuration option (see Python368_Scons311_Path_specified.txt).
With SCons version 4.1.0 installed, the compilation works just fine and as you can see, there the correct gfortran compilation commands are invoked (see Python368_Scons410.txt).

If you need any further information or log files, please let me know.

Best regards,
David
Python368_Scons311_Cantera2.5.0a4.txt
Python368_Scons311_Path_specified.txt
Python368_Scons311.txt
Python368_Scons410.txt

Ray Speth

unread,
Jun 11, 2021, 10:44:32 AM6/11/21
to Cantera Users' Group
Hi David,

Can you provide the output of running the command `scons dump`? We try to set all the variables that SCons uses to pick the Fortran compiler to point to the same binary, but that's apparently not working here.

Thanks,
Ray

Bryan Weber

unread,
Jun 13, 2021, 6:53:10 PM6/13/21
to Cantera Users' Group
Hi David,

Just FYI that my pull request fixing the NameErrors was just merged, so you can rebase your feature work onto the main branch.

Best,
Bryan

On Thursday, June 10, 2021 at 7:17:49 AM UTC-4 divad.s...@gmail.com wrote:

David Schmider

unread,
Jun 14, 2021, 8:41:10 AM6/14/21
to Cantera Users' Group
Hi all,

@Ray: Please find attached the output of scons dump.

@Bryan: Thanks for the information.

Best regards,
David

scons_dump.txt

Ray Speth

unread,
Jun 14, 2021, 9:55:58 AM6/14/21
to Cantera Users' Group

Hi David,

Thanks for the update. It looks like SCons is doing something weird here. I’ve created a pull request with what I think should be a fix. Can you try checking out the branch of the code from https://github.com/Cantera/cantera/pull/1057 to see if it works for you, if you remove the line from your cantera.conf explicitly disabling the Fortran interface?

Thanks,
Ray

David Schmider

unread,
Jun 15, 2021, 1:25:09 AM6/15/21
to Cantera Users' Group
Hi Ray,

great, that works! Thanks for digging into that. See the attached log file.

Best regards,
David

fix-f90-shared_scons.txt
Reply all
Reply to author
Forward
0 new messages