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

foreign_library with c++ files does not add stdc++ dependency #4847

Closed
recoules opened this issue Aug 5, 2021 · 1 comment · Fixed by #5249
Closed

foreign_library with c++ files does not add stdc++ dependency #4847

recoules opened this issue Aug 5, 2021 · 1 comment · Fixed by #5249
Assignees

Comments

@recoules
Copy link
Contributor

recoules commented Aug 5, 2021

Expected Behavior

Be able to compile an executable in bytecode while linking with a library containing c++ foreign_archive.

To do so, the ocamlmklib should be invoked with -lstdc++.

Dynamique section
$ readelf -d _build/default/lib/dllhello_world.so 

Dynamic section at offset 0x2db0 contains 27 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x1000
 0x000000000000000d (FINI)               0x11bc
 0x0000000000000019 (INIT_ARRAY)         0x3d98
 0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x3da8
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x2f0
 0x0000000000000005 (STRTAB)             0x420
 0x0000000000000006 (SYMTAB)             0x318
 0x000000000000000a (STRSZ)              309 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x3fa0
 0x0000000000000002 (PLTRELSZ)           72 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x6b0
 0x0000000000000007 (RELA)               0x5c0
 0x0000000000000008 (RELASZ)             240 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x570
 0x000000006fffffff (VERNEEDNUM)         2
 0x000000006ffffff0 (VERSYM)             0x556
 0x000000006ffffff9 (RELACOUNT)          4
 0x0000000000000000 (NULL)               0x0

Actual Behavior

Dynamique section
$ readelf -d _build/default/lib/dllhello_world.so 

Dynamic section at offset 0x2dc0 contains 26 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x1000
 0x000000000000000d (FINI)               0x11bc
 0x0000000000000019 (INIT_ARRAY)         0x3da8
 0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x3db8
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x2f0
 0x0000000000000005 (STRTAB)             0x420
 0x0000000000000006 (SYMTAB)             0x318
 0x000000000000000a (STRSZ)              268 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x3fa0
 0x0000000000000002 (PLTRELSZ)           72 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x658
 0x0000000000000007 (RELA)               0x568
 0x0000000000000008 (RELASZ)             240 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x548
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x52c
 0x000000006ffffff9 (RELACOUNT)          4
 0x0000000000000000 (NULL)               0x0
$ dune build --root .
File "_none_", line 1:
Error: Error on dynamically loaded library: ./lib/dllhello_world.so: ./lib/dllhello_world.so: undefined symbol: _ZSt4cout

Reproduction

  • PR with a reproducing test:
  1. Test foreign library properly add stdc++ dependency #4846

Specifications

  • Version of dune (output of dune --version): 2.9
  • Version of ocaml (output of ocamlc --version): 4.08
  • Operating system (distribution and version): ubuntu 20.04

Additional notes

  • The foreign_library should support library_flags and c_library_flags in order to add other dependencies
  • Would be helpful to be able to create a foreign_library mixing c and c++ files (e.g. (languages c cxx))
@bobot bobot self-assigned this Sep 8, 2021
@bobot
Copy link
Collaborator

bobot commented Nov 21, 2021

@voodoos I'm moving you as assignee since you worked on #5185

@bobot bobot assigned voodoos and unassigned bobot Nov 21, 2021
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

Successfully merging a pull request may close this issue.

3 participants