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

/usr/bin/ld: cannot find -lclang error after executing #4541

Closed
ghost opened this issue Jun 10, 2017 · 17 comments
Closed

/usr/bin/ld: cannot find -lclang error after executing #4541

ghost opened this issue Jun 10, 2017 · 17 comments

Comments

@ghost
Copy link

ghost commented Jun 10, 2017

My code:
I cloned the crystal-lang/crystal_lib, create a file to generate a ZLib Libary (Only for testing) with following code:

@[Include("zlib.h", prefix: %w(zlib_ ZLIB_ ZLib))]
@[Link("zlib")]
lib ZLib
end

Then I ran crystal run src/main.cr -- examples/lib_z.cr and it crashed.

My error:

daniel@daniel-desktop:~/code/crystal_lib$ crystal run src/main.cr -- examples/lib_z.cr 
/usr/bin/ld: cannot find -lclang
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/daniel/.cache/crystal/crystal-run-main.tmp" "${@}"  -rdynamic  `llvm-config-3.6 --ldflags 2>/dev/null || llvm-config-3.5 --ldflags 2>/dev/null || llvm-config --ldflags 2>/dev/null` -lclang -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

I followed the installation introduction and installed everything from the docs. But it still crashed, even after an update. What should I do to fix it?

My specs:
Crystal: Crystal 0.22.0 [3c71228] (2017-04-20) LLVM 3.5.0
Ubuntu: Ubuntu 16.04.2 LTS

@Sija
Copy link
Contributor

Sija commented Jun 10, 2017

I think crystal-lang/crystal_lib issues are more suitable for this.

@ghost
Copy link
Author

ghost commented Jun 10, 2017

@Sija No one is active on there, and the issues will be ignored.

@Sija
Copy link
Contributor

Sija commented Jun 10, 2017

@oltmannsdaniel I'm not sure what do you mean by "no one is active"... Last commit is from 2 days ago and the repo is maintained by the same Crystal core developers. Also, the issues on the tracker are being commented on so there's no reason to say they will be ignored.

I could understand if you'd say it's less active than this one, but nevertheless your issue is strictly related to before-mentioned repo and not the Crystal itself.

@ghost
Copy link
Author

ghost commented Jun 10, 2017

Ok @Sija . But the last issue I opened a month ago didn't get any comment. So I just wanted to try it I've here.

@ghost ghost closed this as completed Jun 10, 2017
@Sija
Copy link
Contributor

Sija commented Jun 10, 2017

@oltmannsdaniel Probably because you've opened it without using search first - which would tell you there's another such issue (crystal-lang/crystal_lib#25) open, making yours a duplicate...

@asterite
Copy link
Member

You just need to install libclang (or libclang-dev, can't remember). Any /usr/bin/ld: cannot find -lxxx error means you need to install libxxx

@ghost
Copy link
Author

ghost commented Jun 11, 2017

@asterite After installing libclang-dev I ran into a new error:

daniel@daniel-desktop:~/code/sandbox/crystal_lib$ crystal run src/main.cr -- examples/lib_git2.cr 
/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/libffi.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/daniel/.cache/crystal/crystal-run-main.tmp" "${@}"  -rdynamic  `llvm-config-3.6 --ldflags 2>/dev/null || llvm-config-3.5 --ldflags 2>/dev/null || llvm-config --ldflags 2>/dev/null` -lclang -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

What I tried:

  • Run sudo ldconfig
  • Added /usr/local/lib to the libary path

@asterite
Copy link
Member

Oh, I don't know about that :-(

@Sija
Copy link
Contributor

Sija commented Jun 11, 2017

@oltmannsdaniel Do you have libffi-dev package installed?

@ghost
Copy link
Author

ghost commented Jun 12, 2017

@Sija Will try that later this day.

@ghost ghost reopened this Jun 12, 2017
@ghost
Copy link
Author

ghost commented Jun 12, 2017

@Sija It is installed.

@ysbaddaden
Copy link
Contributor

@oltmannsdaniel you hit #1269 for some reason, does crystal build --link-flags="-lffi" ... help?

Basically the error messages seems to say that the linker would link against libffi but refuses to, because -lffi isn't in the link command...

@RX14
Copy link
Contributor

RX14 commented Jun 12, 2017

@ysbaddaden I think the libffi error is misleading and it's just plain #1269 somehow.

The solution would be to compile your own native crystal and ditch the omnibus entirely.

@ghost
Copy link
Author

ghost commented Jun 18, 2017

@ysbaddaden @RX14 The link flag isn't working as well. The output was:

daniel@daniel-desktop:~/code/sandbox/crystal_lib$ crystal build --link-flags="-lffi" src/main.cr
/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libffi.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/daniel/code/sandbox/crystal_lib/main" "${@}" -lffi -rdynamic  `llvm-config-3.6 --ldflags 2>/dev/null || llvm-config-3.5 --ldflags 2>/dev/null || llvm-config --ldflags 2>/dev/null` -lclang -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

@sdogruyol
Copy link
Member

Any update on this?

@daniel-Q6wUOI
Copy link

@sdogruyol As @RX14 said, compiling my own crystal worked to that point of time. I currently moved from Crystal to Golang. But I will use Crystal as my Playground again.

@ghost ghost closed this as completed Sep 10, 2017
@sdogruyol
Copy link
Member

Thanks for the update @OLDaniel 👍

This issue was closed.
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

6 participants