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
missing -ltinfo when linking bytecode with -custom #7164
Comments
Comment author: junsli It works for me on Linux. What platform? |
Comment author: @sliquister Linux. configure says tgetent and co are defined by -lcurses, but I $ (cd config/auto-aux/; cc=gcc ./hasgot -lcurses tgetent tgetstr); echo $? However, curses depends on libtinfo, which does define it: $ ldd /lib64/libncurses.so.5 If I add -Wl,--as-needed in the initial value of opts in hasgot, then $ cat /usr/lib64/libtermcap.so And as shown above, ltinfo contains the right symbols. So it looks Given a.c:
$ gcc -c a.c So maybe this is an ok patch: diff --git a/config/auto-aux/hasgot b/config/auto-aux/hasgot -opts="" |
Comment author: @damiendoligez Could you describe what --as-needed is supposed to do? I've read the ld man page and it's not very enlightening. |
Comment author: @sliquister By default, if you give -lfoo to ld/gcc, the exe gets a runtime dependency on foo, even if no symbol is used from that library. (in the context of ocaml, it could be that you're linking a.cmxa, which contains some modules that have dynamic C dependencies on libfoo and some that don't (so it's reasonable for the cmxa will to -lfoo). Even if the ocaml linker decides to link none of the modules from a.cmxa that depend on -lfoo, it still passes -lfoo to the C linker, and so the above means that the executable will depend on libfoo anyway. With -Wl,--as-needed, the C linker will not create a dynamic dependency on libfoo just because of the spurious -lfoo) |
Comment author: @sliquister And perhaps it's clearer if I try to explain what the suggested change to hasgot does in
|
Comment author: @damiendoligez It looks like a problem in our autoconfig scripts, which we are trying to replace with autoconf anyway. In the meantime, I think adding |
Comment author: @xavierleroy "Technical Standard X/Open Curses Issue 4", which is the most authoritative document I could find, states that
So, I think --as-needed doesn't play nice with the curses/terminfo libraries on your system, but that's a problem with your system, not with OCaml. This said, I fully agree with the other comments: 1- ocamlc -custom should not link with -lcurses to begin with, and 2- autoconf might help. I move to close this PR as resolved/no change required. |
Comment author: @xavierleroy Marking as resolved/no change required. |
Comment author: @xavierleroy Also: the dependency on curses/terminfo should go away soon, see #1431 |
Original bug ID: 7164
Reporter: @sliquister
Status: resolved (set by @xavierleroy on 2017-10-15T14:18:59Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.02.3
Category: configure and build/install
Related to: #6735
Monitored by: @gasche @diml
Bug description
I was trying to pass --as-needed to link exes, but when ocamlc links bytecode exes with -custom, it doesn't pass -ltinfo despite depending on it (which I suppose is wrong?), resulting in the failure below.
If I add -ltinfo to Config.bytecomp_c_libraries, it fixes the problem.
Steps to reproduce
$ touch a.ml; ocamlc -verbose a.ml -ccopt -Wl,--as-needed -custom -o a
$DIR/lib/ocaml/libcamlrun.a(terminfo.o): In function
caml_terminfo_resume': terminfo.c:(.text+0x27): undefined reference to
tputs'$DIR/lib/ocaml/libcamlrun.a(terminfo.o): In function
caml_terminfo_standout': terminfo.c:(.text+0x61): undefined reference to
tputs'$DIR/lib/ocaml/libcamlrun.a(terminfo.o): In function
caml_terminfo_backup': terminfo.c:(.text+0x96): undefined reference to
tputs'$DIR/lib/ocaml/libcamlrun.a(terminfo.o): In function
caml_terminfo_setup': terminfo.c:(.text+0x10a): undefined reference to
tgetent'terminfo.c:(.text+0x11d): undefined reference to
tgetnum' terminfo.c:(.text+0x132): undefined reference to
tgetstr'terminfo.c:(.text+0x148): undefined reference to
tgetstr' terminfo.c:(.text+0x15e): undefined reference to
tgetstr'terminfo.c:(.text+0x174): undefined reference to
tgetstr' terminfo.c:(.text+0x199): undefined reference to
tgetstr'$DIR/lib/ocaml/libcamlrun.a(terminfo.o):terminfo.c:(.text+0x1af): more undefined references to `tgetstr' follow
collect2: ld returned 1 exit status
File "a.ml", line 1:
Error: Error while building custom runtime system
The text was updated successfully, but these errors were encountered: