Netgen, compile FreeCAD on Debian Buster with Netgen

Having trouble installing or compiling FreeCAD? Get help here.
User avatar
bernd
Posts: 6649
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Netgen, compile FreeCAD on Debian Buster with Netgen

Postby bernd » Sat Jan 12, 2019 8:45 pm

as a follows up of this topic https://forum.freecadweb.org/viewtopic. ... 55#p279616 I try to compile FreeCAD with Netgen. Without Netgen everything works fine. Here is what I used as cmake ...

Code: Select all

cmake  -DBUILD_QT5=1  -DPYTHON_EXECUTABLE="/usr/bin/python3"  -DOCCT_CMAKE_FALLBACK=True  -DBUILD_FEM_NETGEN=1  -DNETGEN_ROOT=/opt/netgen  ../freecad

on compile I get an error

Code: Select all

...
[ 42%] Building CXX object src/3rdParty/salomesmesh/CMakeFiles/NETGENPlugin.dir/src/NETGENPlugin/NETGENPlugin_Mesher.cpp.o
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp:47:10: fatal error: meshing.hpp: Datei oder Verzeichnis nicht gefunden
 #include <meshing.hpp>
          ^~~~~~~~~~~~~
compilation terminated.
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp:80:10: fatal error: occgeom.hpp: Datei oder Verzeichnis nicht gefunden
 #include <occgeom.hpp>
          ^~~~~~~~~~~~~
compilation terminated.
...

but the files are in place ...

Code: Select all

$ ls /opt/netgen/include/occ/occgeom.hpp 
/opt/netgen/include/occ/occgeom.hpp
$

$ ls /opt/netgen/include/meshing/meshing.hpp 
/opt/netgen/include/meshing/meshing.hpp
$

How do I tell cmake to search for netgen includes in /opt/netgen/include ?


ahh on cmake I get a strange warning in the regard of netgen

Code: Select all

...
-- We guess that libmed was built using hdf5-openmpi version
CMake Warning (dev) at CMakeLists.txt:770 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable NETGEN_ROOT is set to:

    /opt/netgen

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Netgen: /opt/netgen/lib/cmake/netgen
-- Checking for module 'Coin'
...
reox
Posts: 333
Joined: Sat Aug 13, 2016 10:06 am

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby reox » Sun Jan 13, 2019 10:26 am

What is the full line passed to gcc? I would bet that the netgen include path is not set.

Edit: I tried this, and I get the same error:

Code: Select all

[ 70%] Building CXX object src/3rdParty/salomesmesh/CMakeFiles/NETGENPlugin.dir/src/NETGENPlugin/NETGENPlugin_Mesher.cpp.o
cd /build/FreeCAD/obj-x86_64-linux-gnu/src/3rdParty/salomesmesh && /usr/bin/c++  -DCSFDB -DHAVE_CONFIG_H -DHAVE_LIMITS_H -DLIN -DNETGENPlugin_EXPORTS -DNO_PARALLEL_THREADS -DOCCGEOMETRY -DOCC_CONVERT_SIGNALS -D_OCC64 -I/build/FreeCAD/obj-x86_64-linux-gnu -I/build/FreeCAD/obj-x86_64-linux-gnu/src -I/build/FreeCAD/src -I/build/FreeCAD/src/3rdParty/salomesmesh/src/SMDS -I/build/FreeCAD/src/3rdParty/salomesmesh/src/Driver -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverUNV -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverDAT -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverSTL -I/build/FreeCAD/src/3rdParty/salomesmesh/src/StdMeshers -I/build/FreeCAD/src/3rdParty/salomesmesh/inc -I/build/FreeCAD/obj-x86_64-linux-gnu/src/3rdParty/salomesmesh -I/usr/include/occt -I/usr/include/netgen -I/usr/include/vtk-6.3 -I/usr/include/x86_64-linux-gnu -I/usr/include/hdf5/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/include/jsoncpp -I/usr/include/freetype2  -Wall -Wextra -Wno-write-strings -Wall -DHAVE_SWIG=1 -fpermissive -g -O2 -fdebug-prefix-map=/build/FreeCAD=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=c++11 -D_OCC64 -Wno-sign-compare -Wno-reorder -Wno-switch -Wno-unused-variable -Wno-unused-but-set-variable -Wno-comment -Wno-unused-parameter -O3 -DNDEBUG -fPIC   -I/usr/include/openmpi -I/usr/include/hdf5/openmpi -pthread -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -o CMakeFiles/NETGENPlugin.dir/src/NETGENPlugin/NETGENPlugin_Mesher.cpp.o -c /build/FreeCAD/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp
/build/FreeCAD/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp:80:10: fatal error: occgeom.hpp: No such file or directory
 #include <occgeom.hpp>
          ^~~~~~~~~~~~~
compilation terminated.

I have netgen-headers installed. But it looks like /usr/include/netgen/occ is missing as include path... so somewhere either the cmake scripts are wrong or I miss some parameter for cmake too.
Last edited by reox on Mon Jan 14, 2019 10:35 am, edited 1 time in total.
reox
Posts: 333
Joined: Sat Aug 13, 2016 10:06 am

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby reox » Mon Jan 14, 2019 10:33 am

I think i see where this discrepancy comes from... The cmake config FindNETGEN.cmake explicitly adds the subdirectories in /usr/include/netgen, while the cmake configuration supplied with netgen does not. Thus, if you are using netgen directly from debian, find_package(Netgen) will return indeed a package thus this code in FindNETGEN.cmake is not executed.

But what would be the correct way now? Setting the subdirectories in the include path or defining the includes as occ/occgeom.hpp?
User avatar
bernd
Posts: 6649
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby bernd » Mon Jan 14, 2019 5:02 pm

I tried to set the netgen lib and include dirs with cmake option -D but no succes the only directory set is The Netgen_DIR variable. Even cardcoded in findNETGEN.cmake it is not set.

How is it possible to set the netgen include and lib directories ?
reox
Posts: 333
Joined: Sat Aug 13, 2016 10:06 am

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby reox » Mon Jan 14, 2019 9:32 pm

I tried to patch this in the cmake file of salomesmesh but found out that the header files are in two places, see https://packages.debian.org/sid/amd64/n ... s/filelist

The files in /usr/include/netgen/include seem to include the other files again.
Thus this should do the trick:

Code: Select all

--- a/src/3rdParty/salomesmesh/CMakeLists.txt
+++ b/src/3rdParty/salomesmesh/CMakeLists.txt
@@ -20,6 +20,10 @@ if (VTK_OPTIONS)
     add_definitions(${VTK_OPTIONS})
 endif()
 
+if (NOT NETGEN_INCLUDE_DIR)
+    MESSAGE("Netgen include dir is not set!" FATAL_ERROR)
+endif(NOT NETGEN_INCLUDE_DIR)
+
 include_directories(
     src/SMDS
     src/Driver
@@ -35,6 +39,17 @@ include_directories(
     ${OCC_INCLUDE_DIR}
     ${NGLIB_INCLUDE_DIR}
     ${NETGEN_INCLUDE_DIRS}
+    ${NETGEN_INCLUDE_DIR}/include
     ${ZLIB_INCLUDE_DIR}
     ${VTK_INCLUDE_DIRS}
     ${HDF5_INCLUDE_DIR}

But this raises a ton of new errors like:

Code: Select all

Building CXX object src/3rdParty/salomesmesh/CMakeFiles/NETGENPlugin.dir/src/NETGENPlugin/NETGENPlugin_Mesher.cpp.o
cd /build/FreeCAD/obj-x86_64-linux-gnu/src/3rdParty/salomesmesh && /usr/bin/ccache /usr/lib/ccache/c++  -DCSFDB -DHAVE_CONFIG_H -DHAVE_LIMITS_H -DLIN -DNETGENPlugin_EXPORTS -DNO_PARALLEL_THREADS -DOCCGEOMETRY -DOCC_CONVERT_SIGNALS -D_OCC64 -I/build/FreeCAD/obj-x86_64-linux-gnu -I/build/FreeCAD/obj-x86_64-linux-gnu/src -I/build/FreeCAD/src -I/build/FreeCAD/src/3rdParty/salomesmesh/src/SMDS -I/build/FreeCAD/src/3rdParty/salomesmesh/src/Driver -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverUNV -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverDAT -I/build/FreeCAD/src/3rdParty/salomesmesh/src/DriverSTL -I/build/FreeCAD/src/3rdParty/salomesmesh/src/StdMeshers -I/build/FreeCAD/src/3rdParty/salomesmesh/inc -I/build/FreeCAD/obj-x86_64-linux-gnu/src/3rdParty/salomesmesh -I/usr/include/occt -I/usr/include/netgen -I/usr/include/netgen/include -I/usr/include/vtk-6.3 -I/usr/include/x86_64-linux-gnu -I/usr/include/hdf5/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/include/jsoncpp -I/usr/include/freetype2  -Wall -Wextra -Wno-write-strings -Wall -DHAVE_SWIG=1 -fpermissive -g -O2 -fdebug-prefix-map=/build/FreeCAD=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=c++11 -D_OCC64 -Wno-sign-compare -Wno-reorder -Wno-switch -Wno-unused-variable -Wno-unused-but-set-variable -Wno-comment -Wno-unused-parameter -O3 -DNDEBUG -fPIC   -I/usr/include/openmpi -I/usr/include/hdf5/openmpi -pthread -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -o CMakeFiles/NETGENPlugin.dir/src/NETGENPlugin/NETGENPlugin_Mesher.cpp.o -c /build/FreeCAD/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp
In file included from /usr/include/netgen/include/../general/myadt.hpp:17,
                 from /usr/include/netgen/include/../meshing/../include/myadt.hpp:1,
                 from /usr/include/netgen/include/../meshing/meshing.hpp:6,
                 from /usr/include/netgen/include/meshing.hpp:1,
                 from /usr/include/netgen/include/../occ/occgeom.hpp:12,
                 from /usr/include/netgen/include/occgeom.hpp:1,
                 from /build/FreeCAD/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp:80:
/usr/include/netgen/include/../general/../include/mydefs.hpp:26: warning: "DLL_HEADER" redefined
       #define DLL_HEADER __attribute__ ((visibility ("default")))
 
In file included from /build/FreeCAD/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx:42,
                 from /build/FreeCAD/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp:30:
/usr/include/netgen/nglib.h:33: note: this is the location of the previous definition
    #define DLL_HEADER

For me this looks like that netgen requires some (better) import guards.

It is also interesting, that the header files directly in /usr/include/netgen are from libnglib-dev but the others are from netgen-headers, which depends on libnglib-dev.
The problem seems to be, if somewhere nglib.h is included, the build breaks as nglib.h redefines stuff from netgen-headers but does not guard it.
User avatar
sgrogan
Posts: 4653
Joined: Wed Oct 22, 2014 5:02 pm

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby sgrogan » Mon Jan 14, 2019 10:29 pm

from Windows, I will try to post linux later
Capture.PNG
Capture.PNG (77.07 KiB) Viewed 55 times
The key is that the headers are in 2 places, there are a lot of paths to be set for the headers from the netgen headers package,you can get the paths from reox's link.
Finding the netgen-headers has always been a problem.
reox
Posts: 333
Joined: Sat Aug 13, 2016 10:06 am

Re: Netgen, compile FreeCAD on Debian Buster with Netgen

Postby reox » Tue Jan 15, 2019 6:51 am

But what about the double defines? It looks like you should either use netgen-headers if you want to use the internal functions or libnglib-dev if you want to use nglib, i.e. external functions. but salomesmesh seems to use both, thus it get's confused which headers to use.
There is nginterface_v2.hpp in netgen-headers but it has a different namespace than nglib.h. idk which one would be correct or if there is a hack to make it work.
I tried to include all directories except /usr/include/netgen/include but it looks like that some classes include from the include directory, so you end up with the same problem.