Error importing netgen.gui

Hi,
I rebuilt NGsolve/Netgen from source yesterday on Ubuntu with no errors, but I got the following runtime error when importing netgen.gui:

In [2]: import netgen.gui

TclError Traceback (most recent call last)
in ()
----> 1 import netgen.gui

~/ngsuite/ngsolve-install/lib/python3/dist-packages/netgen/gui.py in ()
20
21 if not netgen.libngpy._meshing._netgen_executable_started:
—> 22 StartGUI()

~/ngsuite/ngsolve-install/lib/python3/dist-packages/netgen/gui.py in StartGUI()
9 win.tk.eval(‘lappend ::auto_path ’ + netgen._netgen_bin_dir)
10 # load with absolute path to avoid issues on MacOS
—> 11 win.tk.eval(‘load "’+netgen._netgen_lib_dir.replace(’\‘,’/‘)+’/libgui[info sharedlibextension]" gui’)
12 win.tk.eval( netgen.libngpy._meshing._ngscript)
13

TclError: couldn’t load file “/home/dow/ngsuite/ngsolve-install/lib/libgui.so”: /home/dow/ngsuite/ngsolve-install/lib/libgui.so: undefined symbol: XmuLookupStandardColormap

I was thinking it might have something to do with this commit yesterday

Thanks!
Dow

Hi Dow,

Which Ubuntu version are you using?

It is probably connected to to the commit you mentioned (and others before it that touched the build system). Please post the output of

ldd /home/dow/ngsuite/ngsolve-install/lib/libgui.so

and the contents of

/home/dow/ngsuite/ngsolve-build/netgen/netgen/CMakeCache.txt

Thanks,
Matthias

Hi Matthias,

It’s actually Linux Mint 18.2 so it corresponds to Ubuntu 16.04.

$ ldd /home/dow/ngsuite/ngsolve-install/lib/libgui.so

linux-vdso.so.1 =>  (0x00007ffcc69d9000)
libnglib.so => /home/dow/ngsuite/ngsolve-install/lib/libnglib.so (0x00007fc0eddee000)
libtcl8.6.so => /usr/lib/x86_64-linux-gnu/libtcl8.6.so (0x00007fc0eda3f000)
libtk8.6.so => /usr/lib/x86_64-linux-gnu/libtk8.6.so (0x00007fc0ed6e2000)
libstlvis.so => /home/dow/ngsuite/ngsolve-install/lib/libstlvis.so (0x00007fc0ed4bf000)
libgeom2dvis.so => /home/dow/ngsuite/ngsolve-install/lib/libgeom2dvis.so (0x00007fc0ed2bb000)
libinterface.so => /home/dow/ngsuite/ngsolve-install/lib/libinterface.so (0x00007fc0ed064000)
libgeom2d.so => /home/dow/ngsuite/ngsolve-install/lib/libgeom2d.so (0x00007fc0ece23000)
libstl.so => /home/dow/ngsuite/ngsolve-install/lib/libstl.so (0x00007fc0ecb9e000)
libcsgvis.so => /home/dow/ngsuite/ngsolve-install/lib/libcsgvis.so (0x00007fc0ec97d000)
libcsg.so => /home/dow/ngsuite/ngsolve-install/lib/libcsg.so (0x00007fc0ec67d000)
libmesh.so => /home/dow/ngsuite/ngsolve-install/lib/libmesh.so (0x00007fc0ec194000)
libvisual.so => /home/dow/ngsuite/ngsolve-install/lib/libvisual.so (0x00007fc0ebf39000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc0ebd35000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007fc0ebac1000)
libGLU.so.1 => /usr/lib/x86_64-linux-gnu/libGLU.so.1 (0x00007fc0eb852000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc0eb4c6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc0eb1bd000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc0eafa5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc0eabdb000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc0ea9be000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc0ea7a4000)
libXft.so.2 => /usr/lib/x86_64-linux-gnu/libXft.so.2 (0x00007fc0ea58f000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fc0ea34c000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fc0ea012000)
libXss.so.1 => /usr/lib/x86_64-linux-gnu/libXss.so.1 (0x00007fc0e9e0e000)
libpython3.5m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007fc0e9787000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc0ee23b000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fc0e955e000)
libxcb-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007fc0e935b000)
libxcb-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007fc0e9158000)
libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fc0e8f51000)
libxshmfence.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007fc0e8d4e000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007fc0e8b1d000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fc0e890b000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fc0e8708000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fc0e8502000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007fc0e8300000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007fc0e80e7000)
libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007fc0e7ee2000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fc0e7cc0000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fc0e7aba000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007fc0e78a8000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fc0e75fe000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fc0e73f4000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fc0e71f1000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fc0e6fed000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fc0e6de7000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fc0e6bc2000)

I attached /home/dow/ngsuite/ngsolve-build/netgen/netgen/CMakeCache.txt

Best,
Dow

Attachment: CMakeCache.txt

That’s strange, libgui.so should to X11_Xmu_LIB (in your case /usr/lib/x86_64-linux-gnu/libXmu.so), as stated in external_dependencies/netgen/ng/CMakeLists.txt:28

target_link_libraries( gui PRIVATE ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} ${LIBTOGL} )

Please check that
[ul]
[li]the line above appears in ng/CMakeLists.txt (i.e. you have the latest source code of Netgen[/li]
[li]libgui.so is linked correctly, please check/attach your_build_dir/netgen/netgen/ng/CMakeFiles/gui.dir/link.txt[/li]
[li]There are no other versions of Netgen/NGSolve installed, check with python3 -c'import ngsolve; print(ngsolve.__file__)'
to see where NGSolve is found[/li]
[/ul]

Best,
Matthias

Hi Matthias,

I’m working at home today so I don’t have immediate access to the Linux mint machine, but I just did a full build from source on my Ubuntu 18.04.1 LTS machine and got the same error. I forgot to mention earlier, but on both machines I’m able to run netgen without any errors. The only error is on import netgen.gui from python3 or jupyter.

$ netgen NETGEN-6.2-dev 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.1809-135-g9f2684ab Using Lapack Including sparse direct solver UMFPACK Running parallel using 4 thread(s) importing NGSolve-6.2.1809-135-g9f2684ab Thank you for using NGSolve
Here is the ldd output on this Ubuntu 18.04 machine:

[code]$ ldd /home/dow/ngsuite/ngsolve-install/lib/libgui.so
linux-vdso.so.1 (0x00007ffc045fa000)
libnglib.so => /home/dow/ngsuite/ngsolve-install/lib/libnglib.so (0x00007f912c507000)
libtcl8.6.so => /usr/lib/x86_64-linux-gnu/libtcl8.6.so (0x00007f912c156000)
libtk8.6.so => /usr/lib/x86_64-linux-gnu/libtk8.6.so (0x00007f912bdfc000)
libstlvis.so => /home/dow/ngsuite/ngsolve-install/lib/libstlvis.so (0x00007f912bbd9000)
libgeom2dvis.so => /home/dow/ngsuite/ngsolve-install/lib/libgeom2dvis.so (0x00007f912b9d5000)
libinterface.so => /home/dow/ngsuite/ngsolve-install/lib/libinterface.so (0x00007f912b77e000)
libgeom2d.so => /home/dow/ngsuite/ngsolve-install/lib/libgeom2d.so (0x00007f912b53d000)
libstl.so => /home/dow/ngsuite/ngsolve-install/lib/libstl.so (0x00007f912b2b8000)
libcsgvis.so => /home/dow/ngsuite/ngsolve-install/lib/libcsgvis.so (0x00007f912b097000)
libcsg.so => /home/dow/ngsuite/ngsolve-install/lib/libcsg.so (0x00007f912ad96000)
libmesh.so => /home/dow/ngsuite/ngsolve-install/lib/libmesh.so (0x00007f912a8ac000)
libvisual.so => /home/dow/ngsuite/ngsolve-install/lib/libvisual.so (0x00007f912a651000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f912a44d000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007f912a1c1000)
libGLU.so.1 => /usr/lib/x86_64-linux-gnu/libGLU.so.1 (0x00007f9129f52000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9129bc9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f912982b000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9129613000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9129222000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9129003000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f9128de6000)
libXft.so.2 => /usr/lib/x86_64-linux-gnu/libXft.so.2 (0x00007f9128bd1000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f912898c000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f9128654000)
libXss.so.1 => /usr/lib/x86_64-linux-gnu/libXss.so.1 (0x00007f9128450000)
libpython3.6m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0 (0x00007f9127da4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f912c954000)
libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f9127b73000)
libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f91278bd000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f9127609000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f91273ff000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f91271cd000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f9126fa5000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f9126d93000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f9126b90000)
libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f912695e000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f912675a000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f9126554000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f912633f000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9126137000)

[/code]Again we’re not seeing a dependency on libXmu.so. I checked and that library is installed at the location you said: /usr/lib/x86_64-linux-gnu/libXmu.so

I do have the latest version of the source and the CMakeLists.txt is specifying X11_Xmu_Lib

    target_link_libraries( gui PRIVATE ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} ${LIBTOGL} )

Here are the contents of gui.dir/link.txt (which contain the -lXmu flag):

$ cat link.txt /usr/bin/c++ -fPIC -march=native -O2 -g -DNDEBUG -shared -Wl,-soname,libgui.so -o libgui.so CMakeFiles/gui.dir/gui.cpp.o CMakeFiles/gui.dir/ngpkg.cpp.o CMakeFiles/gui.dir/demoview.cpp.o CMakeFiles/gui.dir/parallelfunc.cpp.o CMakeFiles/gui.dir/__/libsrc/stlgeom/stlpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/visualization/visualpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/csg/csgpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/geom2d/geom2dpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/occ/occpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/occ/vsocc.cpp.o -Wl,-rpath,/home/dow/ngsuite/ngsolve-build/netgen/netgen/nglib:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/stlgeom:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/geom2d:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/interface:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/csg:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/meshing:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/visualization: ../nglib/libnglib.so -lz -lXmu -lX11 Togl2.1/libtogl.a -ltcl -ltk ../libsrc/stlgeom/libstlvis.so ../libsrc/geom2d/libgeom2dvis.so ../libsrc/interface/libinterface.so ../libsrc/geom2d/libgeom2d.so ../libsrc/stlgeom/libstl.so ../libsrc/csg/libcsgvis.so ../libsrc/csg/libcsg.so ../libsrc/meshing/libmesh.so -lz ../libsrc/visualization/libvisual.so -lpython3.6m -ldl -lGL -lGLU

I only have one instance of NGSolve installed.

$ python3 -c'import ngsolve; print(ngsolve.__file__)' importing NGSolve-6.2.1809-135-g9f2684ab /home/dow/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/__init__.py

Before building this time, I deleted the entire ngsuite tree and then followed again the instructions to build from source on Linux. As I recall, I was able to build from source on both these machines about 3 weeks ago and did not see the error on import with that build.

Best,
Dow

Hi Matthias,

It seemed that even though the library was listed in the the linker command, it was not being included in the dynamic library because it was not considered “needed” for some reason.

Just to try something, I inserted -Wl,--no-as-needed before -lXmu in the link.txt file, then did make and make install (see the modified link.txt below). Then $ ldd /home/dow/ngsuite/ngsolve-install/lib/libgui.so included in its output the line: libXmu.so.6 => /usr/lib/x86_64-linux-gnu/libXmu.so.6 (0x00007f54452c8000)
That fixed the error with import netgen.gui. Maybe the CMakeLists can be modified with set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")?

Best,
Dow

modified link.txt

/usr/bin/c++ -fPIC -march=native -O2 -g -DNDEBUG -shared -Wl,-soname,libgui.so -o libgui.so CMakeFiles/gui.dir/gui.cpp.o CMakeFiles/gui.dir/ngpkg.cpp.o CMakeFiles/gui.dir/demoview.cpp.o CMakeFiles/gui.dir/parallelfunc.cpp.o CMakeFiles/gui.dir/__/libsrc/stlgeom/stlpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/visualization/visualpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/csg/csgpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/geom2d/geom2dpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/occ/occpkg.cpp.o CMakeFiles/gui.dir/__/libsrc/occ/vsocc.cpp.o -Wl,-rpath,/home/dow/ngsuite/ngsolve-build/netgen/netgen/nglib:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/stlgeom:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/geom2d:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/interface:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/csg:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/meshing:/home/dow/ngsuite/ngsolve-build/netgen/netgen/libsrc/visualization: ../nglib/libnglib.so -lz -Wl,--no-as-needed -lXmu -lX11 Togl2.1/libtogl.a -ltcl -ltk ../libsrc/stlgeom/libstlvis.so ../libsrc/geom2d/libgeom2dvis.so ../libsrc/interface/libinterface.so ../libsrc/geom2d/libgeom2d.so ../libsrc/stlgeom/libstl.so ../libsrc/csg/libcsgvis.so ../libsrc/csg/libcsg.so ../libsrc/meshing/libmesh.so -lz ../libsrc/visualization/libvisual.so -lpython3.6m -ldl -lGL -lGLU

Hi Dow,

I could reproduce the issue on Ubuntu 18.04. As can be seen in your link.txt, libXmu is linked BEFORE togl. Since the linking order matters, it’s not needed at that time and dropped. After that, togl is linked with dependencies on libXmu (which remain undefined).

It’s fixed now on master:
Netgen: 7934a3
NGSolve: c57f7e

Best,
Matthias

Thanks for the fix and for explaining the debugging process so well – these linker issues are quite complicated!

Best,
Dow