TestPathApp fails after CMake Install

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: TestPathApp fails after CMake Install

Post by openBrain »

wmayer wrote: Fri Jan 27, 2023 4:58 pm But we are talking about the VM for the CI and there I guess not much additional software is installed.
I can well hack this on the CI, but this will be a general problem for anybody that want to install a self-compiled version with GCC. ;)
The root cause is the fact what the linker does when building a shared library and when installing it. When you run make to build the binaries then the linker adds the RUNPATH entry that contains a list of the paths to the shared libraries the binary depends on. This explains why you can directly run an application without having to set LD_LIBRARY_PATH fiirst.

When installing the binaries then the linker does some re-linking and cleans up the RUNPATH section again of the target file.
To be honest, I only roughly understand all this ATM. :) I lack some knowledge to get the details. But I think it's not really the reason. :?
Notice both versions (Clang and GCC) use the same linker (namely 'ld').

Anyway, there is a very weird thing. I tried to swap the installed 'PathApp.so' between my GCC and Clang VMs, and failure "follows" the GCC compiled lib :
  • Clang compile+install / original Clang 'PathApp.so' => Works
  • Clang compile+install / replaced GCC 'PathApp.so' => Fails
  • Clang compile+install / replaced GCC 'PathApp.so' / Add 'LD_LIBRARY_PATH' at runtime => Works
  • GCC compile+install / original GCC 'PathApp.so' => Fails
  • GCC compile+install / original GCC 'PathApp.so' / Add 'LD_LIBRARY_PATH' at runtime => Works
  • GCC compile+install / replaced Clang 'PathApp.so' => Works
If you have an idea of what I can deeper test/investigate, feel free to suggest.

EDIT : BTW, the RUNPATH is correct in installed 'FreeCAD' binary and 'Import.so' for both versions, pointing to '/usr/local/lib/'
wmayer
Founder
Posts: 20305
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: TestPathApp fails after CMake Install

Post by wmayer »

To be honest, I only roughly understand all this ATM
Here some links:
https://amir.rachum.com/blog/2016/09/17 ... libraries/
https://jeremimucha.com/2021/04/cmake-f ... als-part8/
https://dev.my-gate.net/2021/08/04/unde ... ith-cmake/

EDIT : BTW, the RUNPATH is correct in installed 'FreeCAD' binary and 'Import.so' for both versions, pointing to '/usr/local/lib/'
Just tried the make install using clang on my new system and there it indeed works out of the box. But I am quite sure that on my old system (Xubuntu 18.04) it didn't work either with clang.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: TestPathApp fails after CMake Install

Post by openBrain »

I found this one for GCC as this is the one having troubles : https://www.cprogramming.com/tutorial/s ... x-gcc.html :)

Will try to document myself but I'm a bit lost as I can't really get why the GCC compiled lib needs the 'LD_LIBRARY_MATH' while the Clang one doesn't, given that both are installed in the same location, with the same RUNPATH (and same in 'Import.so' too) ...
wmayer
Founder
Posts: 20305
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: TestPathApp fails after CMake Install

Post by wmayer »

MATH or PATH? :)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: TestPathApp fails after CMake Install

Post by openBrain »

PATH of course. You're merciless. :lol:
vm4dim
Posts: 130
Joined: Tue Nov 23, 2021 1:05 am

Re: TestPathApp fails after CMake Install

Post by vm4dim »

Seems problem is in libarea-native.so

RUNPATH in installed-version libarea-native.so is different from other libs(.so)
In build-version all ok.

Add:
If set NEW_RPATH for libarea-native.so in (BUILD_DIR)/src/Mod/Path/libarea/cmake_install.cmake
same value as for area.so and run "make install", it will work.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: TestPathApp fails after CMake Install

Post by openBrain »

vm4dim wrote: Tue Jan 31, 2023 6:09 pm Add:
If set NEW_RPATH for libarea-native.so in (BUILD_DIR)/src/Mod/Path/libarea/cmake_install.cmake
same value as for area.so and run "make install", it will work.
Seems very interesting. Not very clear for me what to do (not a CMake expert :D). May you provide a patch that I can test?
vm4dim
Posts: 130
Joined: Tue Nov 23, 2021 1:05 am

Re: TestPathApp fails after CMake Install

Post by vm4dim »

Contents of this file 'cmake_install.cmake' is created by cmake and may differ in your build.

For: (BUILD_DIR)/src/Mod/Path/libarea/cmake_install.cmake

I assume the current value in line::58 (for libarea-native.so) is

Code: Select all

         NEW_RPATH "")
But it should be the same as in line:81 (for area.so)

Code: Select all

         NEW_RPATH "/usr/local/lib")
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: TestPathApp fails after CMake Install

Post by openBrain »

OK, I did a "random" search and was very surprised to find only one reference to "PathApp" in https://github.com/FreeCAD/FreeCAD/blob ... eLists.txt

I would expect to find lines like

Code: Select all

add_library(PathApp SHARED ???)
and

Code: Select all

INSTALL(TARGETS PathApp DESTINATION ${CMAKE_INSTALL_LIBDIR})
But as I said, I'm really not skilled about all that. May someone help ?
vm4dim
Posts: 130
Joined: Tue Nov 23, 2021 1:05 am

Re: TestPathApp fails after CMake Install

Post by vm4dim »

I am sure this error message is received from libarea-native.so

Code: Select all

FreeCADCmd -t TestPathApp
...
ImportError: Import.so: cannot open shared object file: No such file or directory
If hack libarea-native.so (in install dir)

Code: Select all

sed -i 's/Import.so/ImZZrt.so/' libarea-native.so
new error message will be:

Code: Select all

ImportError: ImZZrt.so: cannot open shared object file: No such file or directory
Post Reply