Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link static library error #21246

Open
waruqi opened this issue Jan 10, 2023 · 2 comments
Open

Link static library error #21246

waruqi opened this issue Jan 10, 2023 · 2 comments

Comments

@waruqi
Copy link

waruqi commented Jan 10, 2023

Description

I set --nimMainPrefix:libfoo, but it still does not work.

#19830
xmake-io/xmake#3273

test project: https://github.com/xmake-io/xmake/tree/master/tests/projects/nim/static_library

Nim Version

Nim Compiler Version 1.6.10 [Linux: amd64]

Current Output

ruki@4db94baa81bc:/mnt/xmake/tests/projects/nim/static_library$ xmake f -c;xmake -rv
checking for platform ... linux
checking for architecture ... x86_64
checking for nim ... /tmp/nim-1.6.10/bin//nim
checking for the nim compiler (nc) ... nim
checking for /tmp/nim-1.6.10/bin//nim ... ok
checking for flags (-d:release) ... ok
[ 33%]: linking.release libfoo.a
checking for nim ... /tmp/nim-1.6.10/bin//nim
checking for the nim static library archiver (ncar) ... nim
/tmp/nim-1.6.10/bin//nim c -d:release --nimcache:build/.gens/foo/linux/x86_64/release/nimcache --app:staticlib --noMain --passL:-s --nimMainPrefix:libfoo -o:build/linux/x86_64/release/libfoo.a src/foo.nim
[ 66%]: linking.release test
checking for nim ... /tmp/nim-1.6.10/bin//nim
checking for the nim linker (ncld) ... nim
/tmp/nim-1.6.10/bin//nim c -d:release --nimcache:build/.gens/test/linux/x86_64/release/nimcache --passL:-Lbuild/linux/x86_64/release --passL:-s --passL:-lfoo -o:build/linux/x86_64/release/test src/main.nim
error: Hint: used config file '/tmp/nim-1.6.10/config/nim.cfg' [Conf]
Hint: used config file '/tmp/nim-1.6.10/config/config.nims' [Conf]
.........................................................
Hint:  [Link]
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o): in function `NimMainInner':
@mfoo.nim.c:(.text+0x0): multiple definition of `NimMainInner'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:@mmain.nim.c:(.text+0x10): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o): in function `PreMainInner':
@mfoo.nim.c:(.text+0x10): multiple definition of `PreMainInner'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:@mmain.nim.c:(.text+0x0): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o): in function `PreMain':
@mfoo.nim.c:(.text+0x1b0): multiple definition of `PreMain'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:@mmain.nim.c:(.text+0x70): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o): in function `NimMainModule':
@mfoo.nim.c:(.text+0x290): multiple definition of `NimMainModule'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:@mmain.nim.c:(.text+0x150): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o):(.bss+0x0): multiple definition of `gEnv'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:(.bss+0x0): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o):(.bss+0x8): multiple definition of `cmdLine'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:(.bss+0x8): first defined here
/usr/bin/ld: build/linux/x86_64/release/libfoo.a(@mfoo.nim.c.o):(.bss+0x10): multiple definition of `cmdCount'; /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o:(.bss+0x10): first defined here
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc   -o /mnt/xmake/tests/projects/nim/static_library/build/linux/x86_64/release/test  /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@m..@s..@s..@s..@s..@s..@s..@stmp@snim-1.6.10@slib@sstd@sprivate@sdigitsutils.nim.c.o /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@m..@s..@s..@s..@s..@s..@s..@stmp@snim-1.6.10@slib@ssystem@sdollars.nim.c.o /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@m..@s..@s..@s..@s..@s..@s..@stmp@snim-1.6.10@slib@ssystem@sio.nim.c.o /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@m..@s..@s..@s..@s..@s..@s..@stmp@snim-1.6.10@slib@ssystem.nim.c.o /mnt/xmake/tests/projects/nim/static_library/build/.gens/test/linux/x86_64/release/nimcache/@mmain.nim.c.o   -Lbuild/linux/x86_64/release -s -lfoo  -ldl'



### Expected Output

```text
work

Possible Solution

No response

Additional Information

No response

@waruqi
Copy link
Author

waruqi commented Jan 11, 2023

I used --passL:-Wl,--allow-multiple-definition, it works now.

@waruqi
Copy link
Author

waruqi commented Aug 6, 2023

Hello! I'm having similar issue trying to build a static lib in Nim and then use an other Nim script to import the lib. (It's for testing only). I got similar issue and add --passL:-Wl,--allow-multiple-definition to Nim worked for me.

It does not work now.

ld: unknown option: --allow-multiple-definition
clang: error: linker command failed with exit code 1 (use -v to see invocati
on)

xmake-io/xmake#4042 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant