How to load an shared object that also depends on clang/llvm in cling?

I probably have some misconfigured cmake build scripts, but the situation is as follows:

I have a program that depends on clang/llvm (libclang) to do some analysis on a C++ codebase. I didn’t write this program, I just patched it to generate a .so instead of a .a, so that I can load it in cling with .L mylib.so.

When I do this, I get the following output (yes, it’s a pretty old cling build):

$ /nix/store/f2klcja64zjcfa19354lbwd5r3g914qb-cling-unstable-2018-11-20/bin/cling 

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ .L libapiextractor_sh.so
: CommandLine Error: Option 'help-list' registered more than once!
>>> Caught an interpreter exception!
>>> inconsistency in registered CommandLine options
[cling]$ 

My hypothesis is that this means it’s trying to load libclang twice - once for cling and once for my program - and doesn’t like that. What do I do?

This is the cmake code:

add_library(apiextractor_sh SHARED ${apiextractor_SRC})
target_include_directories(apiextractor_sh PRIVATE ${CLANG_EXTRA_INCLUDES}
                                                ${CMAKE_CURRENT_SOURCE_DIR}
                                                ${CMAKE_CURRENT_BINARY_DIR}
                                                ${CMAKE_CURRENT_SOURCE_DIR}/parser)
target_link_libraries(apiextractor_sh PUBLIC Qt5::Core)
target_link_libraries(apiextractor_sh PRIVATE ${CLANG_EXTRA_LIBRARIES})

where ${CLANG_EXTRA_LIBRARIES} contains some variant of libclang.

Ah, one more thing, ldd says not a dynamic executable, so I guess my cling is statically compiled.
Correction: I was looking at the distro generated wrapper script for the cling binary, it is a dynamic executable, and the objdump output:

/nix/store/f2klcja64zjcfa19354lbwd5r3g914qb-cling-unstable-2018-11-20/bin/.cling-wrapped:     file format elf64-x86-64
/nix/store/f2klcja64zjcfa19354lbwd5r3g914qb-cling-unstable-2018-11-20/bin/.cling-wrapped
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000997fd0

Program Header:
    PHDR off    0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3
         filesz 0x00000000000002a0 memsz 0x00000000000002a0 flags r--
  INTERP off    0x00000000000002e0 vaddr 0x00000000004002e0 paddr 0x00000000004002e0 align 2**0
         filesz 0x0000000000000050 memsz 0x0000000000000050 flags r--
    LOAD off    0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**12
         filesz 0x00000000004de108 memsz 0x00000000004de108 flags r--
    LOAD off    0x00000000004df000 vaddr 0x00000000008df000 paddr 0x00000000008df000 align 2**12
         filesz 0x0000000003321119 memsz 0x0000000003321119 flags r-x
    LOAD off    0x0000000003801000 vaddr 0x0000000003c01000 paddr 0x0000000003c01000 align 2**12
         filesz 0x0000000000f9a748 memsz 0x0000000000f9a748 flags r--
    LOAD off    0x000000000479be58 vaddr 0x0000000004b9ce58 paddr 0x0000000004b9ce58 align 2**12
         filesz 0x000000000048d180 memsz 0x00000000004da640 flags rw-
 DYNAMIC off    0x0000000004bb5d58 vaddr 0x0000000004fb6d58 paddr 0x0000000004fb6d58 align 2**3
         filesz 0x0000000000000280 memsz 0x0000000000000280 flags rw-
    NOTE off    0x0000000000000330 vaddr 0x0000000000400330 paddr 0x0000000000400330 align 2**2
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
     TLS off    0x000000000479be58 vaddr 0x0000000004b9ce58 paddr 0x0000000004b9ce58 align 2**3
         filesz 0x0000000000000000 memsz 0x0000000000000050 flags r--
EH_FRAME off    0x000000000428bff0 vaddr 0x000000000468bff0 paddr 0x000000000468bff0 align 2**2
         filesz 0x00000000000970cc memsz 0x00000000000970cc flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
   RELRO off    0x000000000479be58 vaddr 0x0000000004b9ce58 paddr 0x0000000004b9ce58 align 2**0
         filesz 0x000000000041b1a8 memsz 0x000000000041b1a8 flags r--

Dynamic Section:
  NEEDED               libpthread.so.0
  NEEDED               librt.so.1
  NEEDED               libdl.so.2
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6
  NEEDED               ld-linux-x86-64.so.2
  RUNPATH              $ORIGIN/../lib:/nix/store/avr2x43njlq4kyb1a9zgrh6fih5fq4si-glibc-2.27/lib:/nix/store/dmgpvd9nl7qa0ydzlqxvdhmxgmq1d1il-gcc-7.4.0-lib/lib
  INIT                 0x00000000008df000
  FINI                 0x0000000003c00110
  INIT_ARRAY           0x0000000004b9ce58
  INIT_ARRAYSZ         0x0000000000000b40
  FINI_ARRAY           0x0000000004b9d998
  FINI_ARRAYSZ         0x0000000000000008
  HASH                 0x0000000000400350
  GNU_HASH             0x00000000004364a8
  STRTAB               0x0000000000576928
  SYMTAB               0x0000000000473fb0
  STRSZ                0x000000000032e7e2
  SYMENT               0x0000000000000018
  DEBUG                0x0000000000000000
  PLTGOT               0x0000000004fb6fd8
  PLTRELSZ             0x0000000000001fc8
  PLTREL               0x0000000000000007
  JMPREL               0x00000000008dc140
  RELA                 0x00000000008bac18
  RELASZ               0x0000000000021528
  RELAENT              0x0000000000000018
  FLAGS                0x0000000000000008
  FLAGS_1              0x0000000000000001
  VERNEED              0x00000000008ba9d8
  VERNEEDNUM           0x0000000000000007
  VERSYM               0x00000000008a510a

Version References:
  required from ld-linux-x86-64.so.2:
    0x0d696913 0x00 23 GLIBC_2.3
  required from libm.so.6:
    0x09691a75 0x00 12 GLIBC_2.2.5
  required from libc.so.6:
    0x06969195 0x00 24 GLIBC_2.15
    0x06969191 0x00 18 GLIBC_2.11
    0x0d696914 0x00 17 GLIBC_2.4
    0x09691974 0x00 16 GLIBC_2.3.4
    0x0d696916 0x00 15 GLIBC_2.6
    0x0d696913 0x00 14 GLIBC_2.3
    0x06969194 0x00 10 GLIBC_2.14
    0x09691a75 0x00 06 GLIBC_2.2.5
  required from libpthread.so.0:
    0x09691a75 0x00 05 GLIBC_2.2.5
  required from libgcc_s.so.1:
    0x0b792653 0x00 30 GCC_3.3
    0x0b792654 0x00 25 GCC_3.4
    0x0b792650 0x00 04 GCC_3.0
  required from libstdc++.so.6:
    0x0297f864 0x00 29 GLIBCXX_3.4.14
    0x0297f867 0x00 28 GLIBCXX_3.4.17
    0x0297f868 0x00 27 GLIBCXX_3.4.18
    0x0297f869 0x00 26 GLIBCXX_3.4.19
    0x0bafd175 0x00 22 CXXABI_1.3.5
    0x0bafd173 0x00 21 CXXABI_1.3.3
    0x0297f872 0x00 20 GLIBCXX_3.4.22
    0x02297f89 0x00 19 GLIBCXX_3.4.9
    0x0297f865 0x00 13 GLIBCXX_3.4.15
    0x0297f861 0x00 11 GLIBCXX_3.4.11
    0x056bafd3 0x00 09 CXXABI_1.3
    0x0297f870 0x00 08 GLIBCXX_3.4.20
    0x08922974 0x00 07 GLIBCXX_3.4
    0x0297f871 0x00 03 GLIBCXX_3.4.21
  required from libdl.so.2:
    0x09691a75 0x00 02 GLIBC_2.2.5

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .interp       00000050  00000000004002e0  00000000004002e0  000002e0  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .note.ABI-tag 00000020  0000000000400330  0000000000400330  00000330  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .hash         00036158  0000000000400350  0000000000400350  00000350  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .gnu.hash     0003db04  00000000004364a8  00000000004364a8  000364a8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .dynsym       00102978  0000000000473fb0  0000000000473fb0  00073fb0  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .dynstr       0032e7e2  0000000000576928  0000000000576928  00176928  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .gnu.version  000158ca  00000000008a510a  00000000008a510a  004a510a  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .gnu.version_r 00000240  00000000008ba9d8  00000000008ba9d8  004ba9d8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .rela.dyn     00021528  00000000008bac18  00000000008bac18  004bac18  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .rela.plt     00001fc8  00000000008dc140  00000000008dc140  004dc140  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .init         00000017  00000000008df000  00000000008df000  004df000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 11 .plt          00001540  00000000008df020  00000000008df020  004df020  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 12 .plt.got      00000028  00000000008e0560  00000000008e0560  004e0560  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 13 .text         0331fb7f  00000000008e0590  00000000008e0590  004e0590  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 14 .fini         00000009  0000000003c00110  0000000003c00110  03800110  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 15 .rodata       00a8aff0  0000000003c01000  0000000003c01000  03801000  2**5
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 16 .eh_frame_hdr 000970cc  000000000468bff0  000000000468bff0  0428bff0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 17 .eh_frame     00478594  00000000047230c0  00000000047230c0  043230c0  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 18 .gcc_except_table 000000f4  0000000004b9b654  0000000004b9b654  0479b654  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 19 .tbss         00000050  0000000004b9ce58  0000000004b9ce58  0479be58  2**3
                  ALLOC, THREAD_LOCAL
 20 .init_array   00000b40  0000000004b9ce58  0000000004b9ce58  0479be58  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 21 .fini_array   00000008  0000000004b9d998  0000000004b9d998  0479c998  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 22 .data.rel.ro  004193b8  0000000004b9d9a0  0000000004b9d9a0  0479c9a0  2**5
                  CONTENTS, ALLOC, LOAD, DATA
 23 .dynamic      00000280  0000000004fb6d58  0000000004fb6d58  04bb5d58  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 24 .got          00001028  0000000004fb6fd8  0000000004fb6fd8  04bb5fd8  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 25 .data         00071fd8  0000000004fb8000  0000000004fb8000  04bb7000  2**5
                  CONTENTS, ALLOC, LOAD, DATA
 26 .bss          0004d4b8  0000000005029fe0  0000000005029fe0  04c28fd8  2**5
                  ALLOC
 27 .comment      00000022  0000000000000000  0000000000000000  04c28fd8  2**0
                  CONTENTS, READONLY

The wrapper script just contains:

#! /nix/store/x6b81sfmbmkmcyqp2rmk6jgsmzvyrjj0-bash-4.4-p23/bin/bash -e
exec -a "$0" "/nix/store/f2klcja64zjcfa19354lbwd5r3g914qb-cling-unstable-2018-11-20/bin/.cling-wrapped"  -idirafter /nix/store/hhvw7iw81jyzi0q9h15csq1a8db66m4d-glibc-2.27-dev/include "${extraFlagsArray[@]}" "$@"

There are some google results in https://www.google.com/search?q=“cling”+“inconsistency+in+registered+CommandLine+options” and https://github.com/symengine/symengine/issues/1473#issuecomment-432130285 seems to be the correct issue, except my shared library doesn’t use dlopen, but I’m not quite sure what I need to do.

I’ve attached the list of symbols exported (?) by my shared library, obtained via nm libapiextractor_sh.so -C:
symlist.txt (199.1 KB)
and the output of objdump -x /libapiextractor_sh.so -C:


libapiextractor_sh.so:     file format elf64-x86-64
libapiextractor_sh.so
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x000000000003d2a0

Program Header:
    LOAD off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**12
         filesz 0x0000000000037ad0 memsz 0x0000000000037ad0 flags r--
    LOAD off    0x0000000000038000 vaddr 0x0000000000038000 paddr 0x0000000000038000 align 2**12
         filesz 0x000000000009e7f5 memsz 0x000000000009e7f5 flags r-x
    LOAD off    0x00000000000d7000 vaddr 0x00000000000d7000 paddr 0x00000000000d7000 align 2**12
         filesz 0x0000000000025abb memsz 0x0000000000025abb flags r--
    LOAD off    0x00000000000fd100 vaddr 0x00000000000fe100 paddr 0x00000000000fe100 align 2**12
         filesz 0x0000000000004fb0 memsz 0x0000000000005190 flags rw-
 DYNAMIC off    0x00000000000fefa8 vaddr 0x00000000000fffa8 paddr 0x00000000000fffa8 align 2**3
         filesz 0x0000000000000260 memsz 0x0000000000000260 flags rw-
EH_FRAME off    0x00000000000e0f40 vaddr 0x00000000000e0f40 paddr 0x00000000000e0f40 align 2**2
         filesz 0x0000000000002acc memsz 0x0000000000002acc flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
   RELRO off    0x00000000000fd100 vaddr 0x00000000000fe100 paddr 0x00000000000fe100 align 2**0
         filesz 0x0000000000004f00 memsz 0x0000000000004f00 flags r--

Dynamic Section:
  NEEDED               libQt5Core.so.5
  NEEDED               libclang.so.7.1
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6
  SONAME               libapiextractor_sh.so
  RUNPATH              /nix/store/zxmcidggfwy1zl6j4nsxh2anvmvdp4jc-qtbase-5.12.0/lib:/nix/store/f1yhwp8yv5n46qkrsc1pdy229rhh2j2h-clang-7.1.0-lib/lib:/nix/store/iykxb0bmfjmi7s53kfg6pjbfpd8jmza6-glibc-2.27/lib:/nix/store/pjx3f50x0qziyivs7rbg5s12p99nn2np-gcc-7.4.0-lib/lib
  INIT                 0x0000000000038000
  FINI                 0x00000000000d67ec
  INIT_ARRAY           0x00000000000fe100
  INIT_ARRAYSZ         0x0000000000000038
  FINI_ARRAY           0x00000000000fe138
  FINI_ARRAYSZ         0x0000000000000008
  HASH                 0x0000000000000200
  GNU_HASH             0x00000000000042b8
  STRTAB               0x0000000000013858
  SYMTAB               0x00000000000074c8
  STRSZ                0x0000000000016cf3
  SYMENT               0x0000000000000018
  PLTGOT               0x0000000000100208
  PLTRELSZ             0x0000000000007b60
  PLTREL               0x0000000000000007
  JMPREL               0x000000000002ff70
  RELA                 0x000000000002b6c8
  RELASZ               0x00000000000048a8
  RELAENT              0x0000000000000018
  FLAGS                0x0000000000000008
  FLAGS_1              0x0000000000000001
  VERNEED              0x000000000002b598
  VERNEEDNUM           0x0000000000000005
  VERSYM               0x000000000002a54c
  RELACOUNT            0x00000000000000ab

Version References:
  required from libgcc_s.so.1:
    0x0b792650 0x00 15 GCC_3.0
  required from libclang.so.7.1:
    0x01b32d01 0x00 05 LLVM_7.1
  required from libstdc++.so.6:
    0x0bafd178 0x00 14 CXXABI_1.3.8
    0x0297f861 0x00 12 GLIBCXX_3.4.11
    0x02297f89 0x00 11 GLIBCXX_3.4.9
    0x056bafd3 0x00 08 CXXABI_1.3
    0x0297f864 0x00 07 GLIBCXX_3.4.14
    0x08922974 0x00 04 GLIBCXX_3.4
  required from libQt5Core.so.5:
    0x08a28112 0x00 13 Qt_5.12
    0x00058a25 0x00 03 Qt_5
  required from libc.so.6:
    0x0d696914 0x00 10 GLIBC_2.4
    0x06969194 0x00 09 GLIBC_2.14
    0x09691a75 0x00 06 GLIBC_2.2.5
    0x09691974 0x00 02 GLIBC_2.3.4

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .hash         000040b4  0000000000000200  0000000000000200  00000200  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .gnu.hash     0000320c  00000000000042b8  00000000000042b8  000042b8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .dynsym       0000c390  00000000000074c8  00000000000074c8  000074c8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .dynstr       00016cf3  0000000000013858  0000000000013858  00013858  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .gnu.version  0000104c  000000000002a54c  000000000002a54c  0002a54c  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .gnu.version_r 00000130  000000000002b598  000000000002b598  0002b598  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .rela.dyn     000048a8  000000000002b6c8  000000000002b6c8  0002b6c8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .rela.plt     00007b60  000000000002ff70  000000000002ff70  0002ff70  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .init         00000017  0000000000038000  0000000000038000  00038000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  9 .plt          00005250  0000000000038020  0000000000038020  00038020  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 10 .plt.got      00000028  000000000003d270  000000000003d270  0003d270  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 11 .text         0009954b  000000000003d2a0  000000000003d2a0  0003d2a0  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 12 .fini         00000009  00000000000d67ec  00000000000d67ec  000d67ec  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 13 .rodata       00009f2d  00000000000d7000  00000000000d7000  000d7000  2**5
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 14 .qtversion    00000010  00000000000e0f30  00000000000e0f30  000e0f30  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 15 .eh_frame_hdr 00002acc  00000000000e0f40  00000000000e0f40  000e0f40  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 16 .eh_frame     00011b5c  00000000000e3a10  00000000000e3a10  000e3a10  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 17 .gcc_except_table 0000754f  00000000000f556c  00000000000f556c  000f556c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 18 .init_array   00000038  00000000000fe100  00000000000fe100  000fd100  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 19 .fini_array   00000008  00000000000fe138  00000000000fe138  000fd138  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 20 .data.rel.ro  00001e68  00000000000fe140  00000000000fe140  000fd140  2**5
                  CONTENTS, ALLOC, LOAD, DATA
 21 .dynamic      00000260  00000000000fffa8  00000000000fffa8  000fefa8  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 22 .got          00002de8  0000000000100208  0000000000100208  000ff208  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 23 .data         000000b0  0000000000103000  0000000000103000  00102000  2**5
                  CONTENTS, ALLOC, LOAD, DATA
 24 .bss          000001e0  00000000001030b0  00000000001030b0  001020b0  2**4
                  ALLOC
 25 .comment      00000011  0000000000000000  0000000000000000  001020b0  2**0
                  CONTENTS, READONLY
SYMBOL TABLE: [snip]

If mylib.so is linked against llvm, the llvm you link against should be compiled with -fvisibility=hidden. This is a limitation which we will work to remove.

I’ve added these to my cmake file:

target_link_options(apiextractor_sh PRIVATE "-fvisibility=hidden")
set_target_properties(apiextractor_sh PROPERTIES
    C_VISIBILITY_PRESET       hidden
    CXX_VISIBILITY_PRESET     hidden
    VISIBILITY_INLINES_HIDDEN YES
)

but symbols like the following still show up:

                 U clang_createIndex@@LLVM_7.1
                 U clang_Cursor_getStorageClass@@LLVM_7.1
                 U clang_Cursor_hasAttrs@@LLVM_7.1
                 U clang_Cursor_isAnonymous@@LLVM_7.1
                 U clang_CXXConstructor_isConvertingConstructor@@LLVM_7.1
                 U clang_CXXConstructor_isCopyConstructor@@LLVM_7.1
                 U clang_CXXConstructor_isDefaultConstructor@@LLVM_7.1
                 U clang_CXXConstructor_isMoveConstructor@@LLVM_7.1

cmake verbose output shows the following linking step:

/nix/store/9i8a5iq1kx2adjklqzf9xwrrsnqqnapf-gcc-wrapper-9.2.0/bin/g++
-fPIC
-I/nix/store/6b0jmkrw6jwrm1kbbgrcfdic7xl4hnn7-clang-7.1.0/include
-O3
-DNDEBUG
-fvisibility=hidden -shared -Wl,-soname,libapiextractor_sh.so -o libapiextractor_sh.so
[lots of .o files] 
/nix/store/masxdbz5mi276impbflnhldwy3wlhr96-qtbase-5.12.6/lib/libQt5Core.so.5.12.6
-lc -lclang

Oh, I misread, the llvm I link against should be compiled with -fvisibility=hidden

Do you have any pointers for how to compile LLVM with -fvisibility=hidden?

Meanwhile I also found https://github.com/root-project/cling/issues/201 on the issue tracker.

Which now mentions:

  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  set(CMAKE_C_VISIBILITY_PRESET hidden)

as the solution,

Thanks, I will try this.

If I try to compile cling with -DCMAKE_CXX_VISIBILITY_PRESET:STRING=hidden -DCMAKE_C_VISIBILITY_PRESET:STRING=hidden passed to cmake, I get a bunch of linking errors (in the tests?)

[...]
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXString.cpp.o                                                                                                                                                                                   
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o                                                                                                                                                                                     
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Indexing.cpp.o                                                                                                                                                                                   
[100%] Linking CXX shared library ../../../../lib/libclang.so                                                                                                                                                                                                                  
[100%] Built target libclang                                                                                                                                                                                                                                                   
Scanning dependencies of target c-index-test                                                                                                                                                                                                                                   
Scanning dependencies of target c-arcmt-test                                                                                                                                                                                                                                   
[100%] Building C object tools/clang/tools/c-arcmt-test/CMakeFiles/c-arcmt-test.dir/c-arcmt-test.c.o                                                                                                                                                                           
[100%] Building C object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o                                                                                                                                                                           
[100%] Building CXX object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o                                                                                                                                                                          
[100%] Linking CXX executable ../../../../bin/c-arcmt-test                                                                                                                                                                                                                     
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: CMakeFiles/c-arcmt-test.dir/c-arcmt-test.c.o: in function `carcmttest_main':                                   
c-arcmt-test.c:(.text.carcmttest_main+0x24): undefined reference to `clang_enableStackTraces'                                                                                                                                                                                  
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0xb5): undefined reference to `clang_getRemappingsFromFileList'                                                                                                      
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0xc5): undefined reference to `clang_remap_getNumFiles'                   
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x10a): undefined reference to `clang_remap_getFilenames'                                                                                                            
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x119): undefined reference to `clang_getCString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x13d): undefined reference to `clang_getCString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x161): undefined reference to `clang_disposeString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x170): undefined reference to `clang_disposeString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x184): undefined reference to `clang_remap_dispose'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x195): undefined reference to `clang_getRemappings'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x1a9): undefined reference to `clang_remap_getNumFiles'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x1f2): undefined reference to `clang_remap_getFilenames'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x201): undefined reference to `clang_getCString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x225): undefined reference to `clang_getCString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x249): undefined reference to `clang_disposeString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x258): undefined reference to `clang_disposeString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-arcmt-test.c:(.text.carcmttest_main+0x26b): undefined reference to `clang_remap_dispose'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: CMakeFiles/c-arcmt-test.dir/c-arcmt-test.c.o: in function `main':
c-arcmt-test.c:(.text.startup.main+0x83): undefined reference to `clang_executeOnThread'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/clang/tools/c-arcmt-test/CMakeFiles/c-arcmt-test.dir/build.make:85: bin/c-arcmt-test] Error 1
make[1]: *** [CMakeFiles/Makefile2:20569: tools/clang/tools/c-arcmt-test/CMakeFiles/c-arcmt-test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable ../../../../bin/c-index-test
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: CMakeFiles/c-index-test.dir/c-index-test.c.o: in function `PrintMemoryUsage':
c-index-test.c:(.text.PrintMemoryUsage+0x23): undefined reference to `clang_getCXTUResourceUsage'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.PrintMemoryUsage+0xa6): undefined reference to `clang_getTUResourceUsageName'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.PrintMemoryUsage+0x11c): undefined reference to `clang_disposeCXTUResourceUsage'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: CMakeFiles/c-index-test.dir/c-index-test.c.o: in function `PrintRange':
c-index-test.c:(.text.PrintRange+0x37): undefined reference to `clang_getRangeStart'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.PrintRange+0x5f): undefined reference to `clang_getSpellingLocation'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.PrintRange+0x82): undefined reference to `clang_getRangeEnd'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.PrintRange+0xac): undefined reference to `clang_getSpellingLocation'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: CMakeFiles/c-index-test.dir/c-index-test.c.o: in function `InclusionVisitor':
c-index-test.c:(.text.InclusionVisitor+0x24): undefined reference to `clang_getFileName'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.InclusionVisitor+0x35): undefined reference to `clang_getCString'
/nix/store/qw8rhqk004qmqgnkvkpj85l1s194ang1-binutils-2.31.1/bin/ld: c-index-test.c:(.text.InclusionVisitor+0x56): undefined reference to `clang_disposeString'

[...]

Is this fine? How do I get past this?

I just saw https://github.com/root-project/cling/commit/09a061dc5d9fd8165efa72a08e7c8a32c2e76f9d , will try backporting to the version I can build.

Edit: wait, thats a 3 month old commit? Is it what I need?

Well, that fails with the same linking problem, so if this is not expected to fail, at least we know it’s probably something to do with my old version.

I’m currently building against these revs;

  clingSrc = fetchFromGitHub {
    owner = "root-project";
    repo = "cling";
    rev = "5789f5b2eb14ff8e14e6297fe3a449d0ef794f17";
    sha256 = "06l0c9p8102prhanhv8xawzq4k8g587d46aykc2y5j7rrzsbs5hs";
  };

  clangSrc = fetchgit {
    url = "http://root.cern.ch/git/clang.git";
    rev = "dd71e0397cfc8667d4c75ef5b4a1b35802608e59"; # cling-patches branch
    sha256 = "1ir1s4wy9683p9wrvra4xb4xqcd0amqnm4wahx1pf72zk2yxw1wh";
  };

  llvmSrc = fetchgit {
    url = "http://root.cern.ch/git/llvm.git";
    rev = "e0b472e46eb5861570497c2b9efabf96f2d4a485"; # cling-patches branch
    sha256 = "0yls35vyfcb14wghryss9xsin4cbpgkqckg72czh5jd2w0vjcmbx";
  };

I don’t have enough CPU to keep rebuilding this in a reasonable amount of time…
I tried some variants but I can’t tell if cmake even properly tried to rebuild whats necessary, or if I broke the linking some other way.

Should this “just work” with the current master?

Hiding the symbols means only static linking exposes them. The tests likely try to link against the shared lib. I would probably disable the tests, or disable shared libraries.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.