Build from source on Windows

1 week 5 days ago #2912 by ddrake
Hi, I'm getting a compile error when I try to build NGSolve from source on Windows 7 with Visual Studio 2015 C++ and Python 3.7. I get the same error if I try to build using the CMake command or from inside Visual Studio.

The error is:
c:\users\dow\ngsuite\src\external_dependencies\netgen\libsrc\core\type_traits.hpp(46): fatal error C1001: An internal error has occurred in the compiler. [C:\Users\Dow\ngsuite\build\netgen\netgen\libsrc\core\ngcore.vcxproj] [C:\Users\Dow\ngsuite\build\netgen\netgen.vcxproj]
8>      (compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\template.cpp', line 13144)
8>       To work around this problem, try simplifying or changing the program near the locations listed above.
8>      Please choose the Technical Support command on the Visual C++
8>       Help menu, or open the Technical Support help file for more information (compiling source file C:\Users\Dow\ngsuite\src\external_dependencies\netgen\libsrc\core\localheap.cpp)
8>      c:\users\dow\ngsuite\src\external_dependencies\netgen\libsrc\core\type_traits.hpp(52): note: see reference to class template instantiation 'ngcore::detail::has_Range<std::T>' being compiled
8>              with
8>              [
8>                  T=std::size_t
8>              ] (compiling source file C:\Users\Dow\ngsuite\src\external_dependencies\netgen\libsrc\core\localheap.cpp)
8>      c:\users\dow\ngsuite\src\external_dependencies\netgen\libsrc\core\type_traits.hpp(46): note: see reference to variable template 'const bool has_range<unsigned __int64>' being compiled (compiling source file C:\Users\Dow\ngsuite\src\external_dependencies\netgen\libsrc\core\localheap.cpp)
8>      c:\users\dow\ngsuite\src\external_dependencies\netgen\libsrc\core\array.hpp(333): note: see reference to class template instantiation 'ngcore::T_Range<std::size_t>' being compiled (compiling source file C:\Users\Dow\ngsuite\src\external_dependencies\netgen\libsrc\core\localheap.cpp)
This is not an urgent issue for me, but I was wondering if there is a work-around. The nightly build works, so I'm guessing that there is just some issue with my build environment.

I'm attaching my CMakeCache.txt. Please let me know if there is more information I can provide.

Best,
Dow
Attachments:

Please Log in or Create an account to join the conversation.

1 week 5 days ago #2913 by christopher
I think VS2015 is too old, they do not support cpp17 fully afaik. And obviously crash on it... Can you use VS 2019? - community edition is free
Best
Christopher
The following user(s) said Thank You: ddrake

Please Log in or Create an account to join the conversation.

1 week 5 days ago - 1 week 4 days ago #2914 by ddrake
Thanks, Christopher! That makes sense. I was following the instructions on the Build on Windows page, which maybe could be updated. They mention:

You need a recent compiler, we advise Microsoft Visual Studio 2015

and
cmake "../src" -DCMAKE_INSTALL_PREFIX="BASEDIR/install" -G "Visual Studio 14 Win64"

Best,
Dow

EDIT: I replaced Python 3.7 with Python 3.8, assuming that the documentation was out of date in that respect also. Then this worked for me to build NGSolve:
cmake "../src" -DCMAKE_INSTALL_PREFIX="BASEDIR/install" -G "Visual Studio 16 2019" -A "x64"
where
BASEDIR
in my case was
C:/Users/Dow/ngsuite
Then I did the step to set environment variables:
cmake --build . --config Release --target set_environment_variables
This prepended
C:/Users/Dow/ngsuite/install
to my PYTHONPATH, but then netgen wasn't able to find the python modules:
C:\Users\Dow>netgen
NETGEN-6.2.2006-8-g2800d6c2
Developed by Joachim Schoeberl at
2010-xxxx Vienna University of Technology
2006-2010 RWTH Aachen University
1996-2006 Johannes Kepler University Linz
optfile ./ng.opt does not exist - using default values
togl-version : 2
loading ngsolve library
NGSolve-6.2.2006-49-ga4dfcd3b
Using Lapack
Including sparse direct solver UMFPACK
Running parallel using 8 thread(s)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ngsolve'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ngsolve'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'netgen'
Thank you for using NGSolve

I tried changing the PYTHONPATH to include
C:/Users/Dow/ngsuite/install/lib/site-packages
Then netgen ran correctly, and I was able to import ngsolve from the netgen python console and run a python script using
netgen myscript.py
The only remaining issue is that if I try to import ngsolve in a regular python shell or in a Jupyter notebook, or run my script using
python myscript.py
, I get the error:
C:\Users\Dow>python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from ngsolve import *
  File "C:\Users\Dow\ngsuite\install\lib\site-packages\ngsolve\__init__.py", lin
e 12, in <module>
    import netgen
  File "C:\Users\Dow\ngsuite\install\lib\site-packages\netgen\__init__.py", line
 13, in <module>
    from . import libngpy
ImportError: DLL load failed while importing libngpy: The specified module could
 not be found.
The package "C:\Users\Dow\ngsuite\install\lib\site-packages\netgen\libngpy.lib" exists as a static library, but the Python 3.8 interpreter seems to be expecting a dynamic load library (dll) perhaps?

Best,
Dow

Please Log in or Create an account to join the conversation.

1 week 3 days ago #2918 by ddrake
Sorry -- I was wrong yesterday when I reported that the build completed correctly. I deleted the build and install directories and repeated the build steps.
cmake "../src" -DCMAKE_INSTALL_PREFIX="BASEDIR/install" -G "Visual Studio 16 2019" -A "x64"
cmake --build . --config Release --target install
This time I noticed an error in the build that I had missed.
...
    -- Installing: C:/UsersDow/ngsuite/install/Lib/site-packages/ngsolve/labextension/labextension
    -- Installing: C:/UsersDow/ngsuite/install/Lib/site-packages/ngsolve/labextension/labextension/plugin.js
    -- Installing: C:/UsersDow/ngsuite/install/Lib/site-packages/ngsolve/labextension/labextension/plugin.js.map
    -- Installing: C:/UsersDow/ngsuite/install/Lib/site-packages/ngsolve/labextension/package.json
    Traceback (most recent call last):
      File "c:\users\dow\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\users\dow\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\Dow\AppData\Local\Programs\Python\Python38\Scripts\jupyter-nbextension.exe\__main__.py", line 7, in <module>
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 270, in launch_instance
        return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
        app.start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 983, in start
        super(NBExtensionApp, self).start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 259, in start
        self.subapp.start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 711, in start
        self.install_extensions()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 682, in install_extensions
        full_dests = install(self.extra_args[0],
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 206, in install_nbextension_python
        m, nbexts = _get_nbextension_metadata(module)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 1117, in _get_nbextension_metadata
        m = import_item(module)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\traitlets\utils\importstring.py", line 42, in import_item
        return __import__(parts[0])
    ModuleNotFoundError: No module named 'ngsolve'
    Traceback (most recent call last):
      File "c:\users\dow\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\users\dow\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\Dow\AppData\Local\Programs\Python\Python38\Scripts\jupyter-nbextension.exe\__main__.py", line 7, in <module>
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 270, in launch_instance
        return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
        app.start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 983, in start
        super(NBExtensionApp, self).start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 259, in start
        self.subapp.start()
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 891, in start
        self.toggle_nbextension_python(self.extra_args[0])
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 864, in toggle_nbextension_python
        return toggle(module,
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 477, in enable_nbextension_python
        return _set_nbextension_state_python(True, module, user, sys_prefix,
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 375, in _set_nbextension_state_python
        m, nbexts = _get_nbextension_metadata(module)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\notebook\nbextensions.py", line 1117, in _get_nbextension_metadata
        m = import_item(module)
      File "c:\users\dow\appdata\local\programs\python\python38\lib\site-packages\traitlets\utils\importstring.py", line 42, in import_item
        return __import__(parts[0])
    ModuleNotFoundError: No module named 'ngsolve'
 ...

I can't find any error preceding this, but there were many warnings about "inconsistent dll linkage".
I'm attaching the configure/build output along with my CMakeCache.txt

I also tried deleting the build and install directories and building in Visual Studio. The documentation says:

Alternatively you can open BASEDIR\build\SUPERBUILD.sln in Visual Studio and build the "INSTALL" project. Make sure to select the desired solution configuration (e.g. Release).

The only '.sln' file in the build directory was 'ngsuite.sln', which I assume is the new name for 'SUPERBUILD.sln'. I built the "INSTALL" project as instructed. The same warnings and errors were generated and the behavior of the installed application was the same (i.e. netgen runs but importing ngsolve in a python shell fails).

I don't know what else to try at this point.

Best,
Dow
Attachments:

Please Log in or Create an account to join the conversation.

1 week 3 days ago #2921 by matthiash
Hi Dow,

I think you need to set the environment variables (like PYTHONPATH):

cmake --build . --config Release --target set_environment_variables

I wasn't aware this is now already needed during the build, we will move this up in the documentation.

Best,
Matthias
The following user(s) said Thank You: ddrake

Please Log in or Create an account to join the conversation.

1 week 3 days ago #2922 by ddrake
Thanks, Matthias!

Your point makes sense. But I think there may also be an issue with the directory that is being added to PYTHONPATH by set_environment_variables.

I just tried removing references to ngsolve directories from my PATH and PYTHONPATH, then running
cmake --build . --config Release --target set_environment_variables
cmake --build . --config Release --target install
The build failed in the same way.

Please Log in or Create an account to join the conversation.

© 2019 Netgen/NGSolve