UG4 / ugcore

The core functionality of UG4. Includes sources, build-scripts, and utility scripts.
https://github.com/UG4/ugcore
Other
36 stars 23 forks source link

Installation problems for tetgen on linux machine #56

Closed annegehrke closed 1 year ago

annegehrke commented 3 years ago

The following error message appeared when I tried to compile UG4 with tetgen (the path to tetgen is correct) on a linux machine:

[ 88%] Linking CXX shared library ../../lib/libug4.so
CMakeFiles/ug4.dir/ugbase/bindings/lua/externals/lua/loslib.c.o: In function `os_tmpname':
loslib.c:(.text+0x21d): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/bin/ld: ../../tools/tetgen/libtet.a(predicates.o): relocation R_X86_64_PC32 against symbol `_Z6dstored' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
ugcore/CMakeFiles/ug4.dir/build.make:11208: die Regel für Ziel „../lib/libug4.so“ scheiterte
make[2]: *** [../lib/libug4.so] Fehler 1
CMakeFiles/Makefile2:105: die Regel für Ziel „ugcore/CMakeFiles/ug4.dir/all“ scheiterte
make[1]: *** [ugcore/CMakeFiles/ug4.dir/all] Fehler 2
Makefile:83: die Regel für Ziel „all“ scheiterte
make: *** [all] Fehler 2

Does anyone have an idea what went wrong?

stephanmg commented 3 years ago

Did you recompile with -fPIC? (position-independent code)

mastep84 commented 3 years ago

Yes, we have tried that already. Unfortunately, the above error remains.

stephanmg commented 3 years ago

Did you use c++filt do demangle the name? It loooks like it is dstore(double). Can you compile tetgen standalone?!

Also much more details are required about the toolchain and the operating system.

mastep84 commented 3 years ago

That's a good point. @annegehrke, could you elaborate on that? Also you could try the suggestion by @stephanmg, typing

echo _Z6dstored | c++filt -s

after you get the build error message. Building tetgen standalone seems to work, at least as library. @annegehrke, maybe try compiling tetgen by

make tetgen

instead of

make tetlib

as well.

bsumirak commented 3 years ago

I'm still betting it's an fPIC issue. The tetgen lib (of the ug4 tool) is statically built without -fPIC added to the compiler flags. When you add the line set_property(TARGET tet PROPERTY POSITION_INDEPENDENT_CODE ON) after the add_library command in tools/tetgen/CMakeLists.txt and recompile, does that resolve the issue?

annegehrke commented 3 years ago

Thank you very much for your contributions!

I tested the advise of @bsumirak but it made no difference (CXXFLAGS = -03 -fPIC was still set). I got the same error message.

It was possible to build the tetgen standalone by typing make tetgen.

@stephanmg Your guess was right: echo _Z6dstored | c++filt yielded dstore(double). What does that mean?

mastep84 commented 3 years ago

FIY:

CXXFLAGS = -03 -fPIC instead of line 22 in the tetgen makefile:

https://github.com/UG4/tool_tetgen/blob/0d664a9831da2292ab48ba44880edd3ebbb211f0/makefile#L22

This has previously resolved the same kind of issue in case of a Ubuntu on Windows Subsystem for Linux build.

stephanmg commented 3 years ago

@annegehrke yeah I checked this already, not really helpful. I think @bsumirak hinting to was a good idea, try if this or @mastep84 version helps.

Btw.: Could you state your OS and toolchain?

bsumirak commented 3 years ago

Pondering this once more, I first want to clarify what your setup is. This is what I gather, correct me if I am wrong:

  1. You used uginstall to download the tetgen sources to $UG4_ROOT/tools/tetgen.
  2. But you do not build it alongside ug4 (with -Dtetgen=ON).
  3. instead you build it separately, using the Makefile included in the tetgen source.
  4. Then you specify -DTETGEN=$UG4_ROOT/tools/tetgen/ during the ug4 cmake setup.

If that is the case, then modifications to the tetgen CMakeFile would not make any difference. But I think I know what is happening nonetheless. Please try the following:

  1. remove $UG4_ROOT/tools/tetgen/predicates.o
  2. add the -fPIC to CXXFLAGS and PREDCXXFLAGS in the makefile
  3. recompile tetlib (make tetlib)
  4. recompile ug4

Working now?

annegehrke commented 3 years ago

@bsumirak Thank you very much for the solution of the problem! You guessed right about my setup and you suggested the right approach :) I could compile ug4 now with tetgen and already tested it by creating a geometry.

Many thanks also to @stephanmg and @mastep84 for your help :)