Skip to content

Build failure on Linux x86_64 (libp2p.so linking phase) #33

@rikettsie

Description

@rikettsie

Hi @gmelodie, @richard-ramos, @iurimatias
I found a problem while building the stack on my Linux x86_64 laptop.
It seems to me that the generated libp2p.so is not correctly located under the ./lib/ directory during the plugin postinstall phase:

> Failed to load plugin at /nix/store/2ikwf6a2lzhlv824wlz7h9fgf7idy9gk-logos-libp2p_module-module-lib-1.0.0/lib/libp2p_module_plugin.so: Cannot load library /nix/store/2ikwf6a2lzhlv824wlz7h9fgf7idy9gk-logos-libp2p_module-module-lib-1.0.0/lib/libp2p_module_plugin.so: libp2p.so: cannot open shared object file: No such file or directory

I didn't have this problem on macOS, only on Linux. Maybe it's something related to my environment, but I managed to fix it by explicitely adding the INSTALL_RPATH "$ORIGIN" (adding a UNIX block in CMakeLists.txt) and by referencing {libp2pCbind system} in the flake.nix.

Diffs:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d43a5c3..1f09cc9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,11 @@ if(APPLE)
         BUILD_RPATH "${CMAKE_CURRENT_SOURCE_DIR}/lib"
         INSTALL_RPATH "@loader_path;@loader_path/../lib"
     )
+elseif(UNIX)
+    set_target_properties(libp2p_module_module_plugin PROPERTIES
+        BUILD_RPATH "${CMAKE_CURRENT_SOURCE_DIR}/lib"
+        INSTALL_RPATH "$ORIGIN"
+    )
 endif()

and

diff --git a/flake.nix b/flake.nix
index aa515c0..d217bb6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -35,8 +35,14 @@
 
           postInstall = ''
             mkdir -p $out/lib
-            cp lib/*.dylib $out/lib/ 2>/dev/null || true
-            cp lib/*.so $out/lib/ 2>/dev/null || true
+            cp ${libp2pCbind system}/lib/*.dylib $out/lib/ 2>/dev/null || true
+            cp ${libp2pCbind system}/lib/*.so $out/lib/ 2>/dev/null || true
           '';
         };

I can provide a concise PR of this or is there a better way to fix this according to you?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions