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

compiler flag --clib prefixes unnecessary path component to library name #16937

Closed
samdmarshall opened this issue Feb 4, 2021 · 2 comments
Closed

Comments

@samdmarshall
Copy link
Contributor

Currently the compiler flag --clib:... prefixes the project src path to the specified C library name.

Example

I have created an example project here: https://github.com/samdmarshall/nim-compiler-clib-bug

The relevant files are the nim.cfg:

--clibdir:"/brew/lib"
--cincludes:"/brew/include"
--clib:"notmuch"

generates the following command:

/brew/bin/ld: cannot find -l/home/demi/Desktop/nim-compiler-clib-bug/src/notmuch
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of an external program failed: 'clang   -o /home/demi/Desktop/nim-compiler-clib-bug/main  /home/demi/.cache/nim/main_d/stdlib_assertions.nim.c.o /home/demi/.cache/nim/main_d/stdlib_io.nim.c.o /home/demi/.cache/nim/main_d/stdlib_system.nim.c.o /home/demi/.cache/nim/main_d/stdlib_parseutils.nim.c.o /home/demi/.cache/nim/main_d/stdlib_strutils.nim.c.o /home/demi/.cache/nim/main_d/stdlib_times.nim.c.o /home/demi/.cache/nim/main_d/stdlib_os.nim.c.o /home/demi/.cache/nim/main_d/stdlib_strformat.nim.c.o /home/demi/.cache/nim/main_d/@mmain.nim.c.o  -lm -lrt   -l/home/demi/Desktop/nim-compiler-clib-bug/src/notmuch -L/brew/lib -ldl'

Current Output

at the end of this command the flags are ordered as such:

-l/home/demi/Desktop/nim-compiler-clib-bug/src/notmuch
-L/brew/lib

Expected Output

-lnotmuch
-L/brew/lib

Possible Solution

currently, using --passL: "-lnotmuch" flag instead of the preferred --clib:"notmuch" flag allows for the correct flags to be passed to the linker.

Additional Information

Nim Compiler:

Nim Compiler Version 1.4.2 [Linux: amd64]
Compiled at 2020-11-30
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 3fb5157ab1b666a5a5c34efde0f357a82d433d04
active boot switches: -d:release
@KamijoToma
Copy link

I met the same question on my project, and I finally build a modified compiler which seems to be worked properly.

Simply, I changed this line to:
conf.cLinkedLibs.add arg
and it seems to link the library without an extra path.

@demotomohiro
Copy link
Contributor

@KamijoToma

I met the same question on my project, and I finally build a modified compiler which seems to be worked properly.

Simply, I changed this line to: conf.cLinkedLibs.add arg and it seems to link the library without an extra path.

Thank you! That fixes this issue.
I have sent PR #19754 to fix this.

capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…iler correctly (nim-lang#19754)

* Fix 16937: Make --clib option works

* Make tests/compiler/tcmdlineclib.nim works from any current dir

* Try to fix link error on macosx

* Add a comment to tests/compiler/tcmdlineclib.nims

Co-authored-by: Clay Sweetser <[email protected]>
narimiran pushed a commit that referenced this issue Apr 24, 2023
…rectly (#19754)

* Fix 16937: Make --clib option works

* Make tests/compiler/tcmdlineclib.nim works from any current dir

* Try to fix link error on macosx

* Add a comment to tests/compiler/tcmdlineclib.nims

Co-authored-by: Clay Sweetser <[email protected]>
(cherry picked from commit 2a34d14)
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

3 participants