Skip to content

Commit

Permalink
attempt to fix dynamic library build error
Browse files Browse the repository at this point in the history
```
/nix/store/mzrw2zphz9xx9s3qq8x5zpf18isp0jga-go-1.20.3/share/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/nix/store/ybw485608d7f1yv1v071j2052q64mvla-binutils-2.40/bin/ld: /build/go-link-2631521468/go.o: relocation R_X86_64_TPOFF32 against `runtime.tlsg' can not be used when making a shared object; recompile with -fPIC
/nix/store/ybw485608d7f1yv1v071j2052q64mvla-binutils-2.40/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
```

Signed-off-by: Jakub Sokołowski <[email protected]>
  • Loading branch information
jakubgs committed Apr 16, 2024
1 parent 1c5684d commit cfba0b9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ endif
dynamic-library:
@echo "Building shared library..."
rm -f ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT)*
$(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) ${GOBIN} build \
${GOBIN} $(GOBIN_SHARED_LIB_CGO_LDFLAGS) build \
-buildmode=c-shared \
-tags="${BUILD_TAGS} gowaku_no_rln" \
-o ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT) \
Expand Down
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
self ? ./.,
subPkgs ? "cmd/waku",
ldflags ? [],
cgoLdflags ? "",
output ? null,
commit ? builtins.substring 0 7 (self.rev or "dirty"),
version ? builtins.readFile ./VERSION,
Expand All @@ -18,6 +19,8 @@ pkgs.buildGo120Module {
"-X github.com/waku-org/go-waku/waku/v2/node.GitCommit=${commit}"
"-X github.com/waku-org/go-waku/waku/v2/node.Version=${version}"
] ++ ldflags;
CGO_LDFLAGS = cgoLdflags;
GOGCCFLAGS = "-fPIC";
doCheck = false;

# Otherwise library would be just called bin/c.
Expand Down
7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
inherit self;
subPkgs = ["library/c"];
ldflags = ["-buildmode=c-shared"];
output = "libgowaku.a";
cgoLdflags = "-Wl,-Bsymbolic,-soname,libgowaku.so.0";
output = "libgowaku.so";
};
});

Expand All @@ -47,7 +48,9 @@
inputsFrom = [ packages.${system}.node ];
buildInputs = with pkgs; [ golangci-lint ];
nativeBuildInputs = lib.optional stdenv.isDarwin [
(pkgs.xcodeenv.composeXcodeWrapper { version = "14.2"; allowHigher = true; })
(pkgs.xcodeenv.composeXcodeWrapper {
version = "14.2"; allowHigher = true;
})
];
};

Expand Down

0 comments on commit cfba0b9

Please sign in to comment.