使用 cmake 與 libldap 的奇怪連結問題

使用 cmake 與 libldap 的奇怪連結問題

我正在嘗試使用 download_an_compile.sh 腳本(使用 CMake 建置二進位檔案)從 FlightGear 專案建立 SimGear。到目前為止,構建進展順利,但是當腳本嘗試將構建的對象文件鏈接到庫時,我得到了大量的信息

//usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2: warning: undefined reference to [email protected]_2

(其中...是每個訊息的不同函數名稱)。現在我想我只需透過添加-DCMAKE_CXX_STANDARD_LIBRARIES="-llber-2.4"到 CMake 的參數來手動指示 CMake 將 lber 庫連結到正在建立的庫。這導致了

/usr/bin/ld: -llber-2.4 could not be found

這對我來說是一個謎,因為它就在那裡:

$ ls /usr/lib/x86_64-linux-gnu | grep lber
liblber-2.4.so.2
liblber-2.4.so.2.10.8

事實上,我不應該收到undefined reference錯誤,因為這些函數都在那裡:

$ nm /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 

$ nm -D /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 | grep ber
0000000000005fe0 T ber_alloc
0000000000005fa0 T ber_alloc_t
0000000000006d50 T ber_bprint
0000000000007ec0 T ber_bvarray_add
0000000000007df0 T ber_bvarray_add_x
0000000000007cd0 T ber_bvarray_dup_x
0000000000007cc0 T ber_bvarray_free
0000000000007c30 T ber_bvarray_free_x
0000000000007830 T ber_bvdup
0000000000007700 T ber_bvecadd
0000000000007650 T ber_bvecadd_x
0000000000007640 T ber_bvecfree
00000000000075c0 T ber_bvecfree_x
00000000000075b0 T ber_bvfree
0000000000007570 T ber_bvfree_x
0000000000007c20 T ber_bvreplace
0000000000007b80 T ber_bvreplace_x
0000000000002c70 T ber_decode_oid
0000000000006fc0 T ber_dump
0000000000006000 T ber_dup
0000000000007820 T ber_dupbv
0000000000007710 T ber_dupbv_x
0000000000004cc0 T ber_encode_oid
0000000000006ab0 T ber_errno_addr
0000000000006a30 T ber_error_print
0000000000003a80 T ber_first_element
0000000000006250 T ber_flatten
0000000000006170 T ber_flatten2
0000000000005f90 T ber_flush
0000000000005db0 T ber_flush2
0000000000005d70 T ber_free
0000000000005d10 T ber_free_buf
00000000000038d0 T ber_get_bitstringa
0000000000003a70 T ber_get_boolean
0000000000003150 T ber_get_enum
0000000000003080 T ber_get_int
0000000000006400 T ber_get_next
0000000000003a20 T ber_get_null
0000000000007ed0 T ber_get_option
0000000000003730 T ber_get_stringa
0000000000003810 T ber_get_stringal
00000000000037a0 T ber_get_stringa_null
0000000000003160 T ber_get_stringb
00000000000031f0 T ber_get_stringbv
0000000000003650 T ber_get_stringbv_null
0000000000002e30 T ber_get_tag
0000000000006380 T ber_init
00000000000060c0 T ber_init2
0000000000006160 T ber_init_w_nullc
000000000020d168 B ber_int_errno_fn
000000000020d178 B ber_int_log_proc
000000000020d190 B ber_int_memory_fns
000000000020d1a0 B ber_int_options
0000000000009590 T ber_int_sb_close
0000000000009610 T ber_int_sb_destroy
0000000000009500 T ber_int_sb_init
0000000000009710 T ber_int_sb_read
00000000000099e0 T ber_int_sb_write
00000000000069d0 T ber_len
0000000000006f70 T ber_log_bprint
00000000000070b0 T ber_log_dump
0000000000007120 T ber_log_sos_dump
0000000000007a50 T ber_mem2bv
0000000000007950 T ber_mem2bv_x
0000000000007460 T ber_memalloc
0000000000007400 T ber_memalloc_x
00000000000074d0 T ber_memcalloc
0000000000007470 T ber_memcalloc_x
0000000000007390 T ber_memfree
0000000000007330 T ber_memfree_x
0000000000007560 T ber_memrealloc
00000000000074e0 T ber_memrealloc_x
00000000000073f0 T ber_memvfree
00000000000073a0 T ber_memvfree_x
0000000000003b00 T ber_next_element
0000000000002e80 T ber_peek_element
0000000000002fd0 T ber_peek_tag
0000000000005370 T ber_printf
00000000000069e0 T ber_ptrlen
0000000000005080 T ber_put_berval
0000000000005100 T ber_put_bitstring
0000000000005290 T ber_put_boolean
0000000000004f30 T ber_put_enum
0000000000004f50 T ber_put_int
0000000000005220 T ber_put_null
0000000000004f70 T ber_put_ostring
0000000000005350 T ber_put_seq
0000000000005360 T ber_put_set
00000000000050b0 T ber_put_string
000000000020d170 B ber_pvt_err_file
0000000000006ad0 T ber_pvt_log_output
000000000020d008 D ber_pvt_log_print
0000000000006c20 T ber_pvt_log_printf
000000000020d1e0 B ber_pvt_opt_on
0000000000008f00 T ber_pvt_sb_buf_destroy
0000000000008ee0 T ber_pvt_sb_buf_init
0000000000009180 T ber_pvt_sb_copy_out
00000000000093b0 T ber_pvt_sb_do_write
0000000000008fe0 T ber_pvt_sb_grow_buffer
00000000000094c0 T ber_pvt_socket_set_nonblock
0000000000005a20 T ber_read
0000000000005ad0 T ber_realloc
0000000000006a20 T ber_remaining
00000000000062f0 T ber_reset
00000000000069f0 T ber_rewind
0000000000003ba0 T ber_scanf
00000000000080f0 T ber_set_option
00000000000059a0 T ber_skip_data
0000000000002f90 T ber_skip_element
0000000000003020 T ber_skip_tag
0000000000008d30 T ber_sockbuf_add_io
0000000000009560 T ber_sockbuf_alloc
0000000000009800 T ber_sockbuf_ctrl
00000000000096a0 T ber_sockbuf_free
000000000020d060 D ber_sockbuf_io_debug
000000000020d0a0 D ber_sockbuf_io_fd
000000000020d0e0 D ber_sockbuf_io_readahead
000000000020d120 D ber_sockbuf_io_tcp
000000000020d020 D ber_sockbuf_io_udp
0000000000008e20 T ber_sockbuf_remove_io
0000000000007130 T ber_sos_dump
00000000000069c0 T ber_start
0000000000005310 T ber_start_seq
0000000000005330 T ber_start_set
0000000000007940 T ber_str2bv
0000000000007840 T ber_str2bv_x
0000000000007ac0 T ber_strdup
0000000000007a60 T ber_strdup_x
0000000000007b70 T ber_strndup
0000000000007b10 T ber_strndup_x
0000000000007ad0 T ber_strnlen
0000000000005c00 T ber_write

ldd也表示libldap正在引用右側liblber

$ ldd /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 | grep lber
    liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f28c8bdc000)

有人有什麼想法嗎?我不……如果我忘記了任何細節,請告訴我,我會添加它們!

答案1

至少在 Debian(及其衍生版本)中,共享庫的開發文件被分成一個單獨的二進位包:

如果共用程式庫有關聯的開發文件,則來源碼包需要產生名為libraryname-dev的二進位開發包,或者如果需要一次支援多個開發版本,則為librarynameapiversion-dev。安裝開發套件必須安裝針對該共用程式庫編譯程式所需的所有開發檔案。

在這種情況下,「開發文件」主要指 C/C++ 頭文件,但重要的是通常包含指向共享庫本身的符號鏈接

開發包應包含關聯共享庫的符號鏈接,不含版本號。例如,libgdbm-dev 軟體包應包含從 /usr/lib/libgdbm.so 到 libgdbm.so.3.0.0 的符號連結。編譯包時鏈接器 (ld) 需要此符號鏈接,因為動態編譯時它只會查找 libgdbm.so。

在這種情況下,儘管您已經擁有共享庫

liblber-2.4.so.2
liblber-2.4.so.2.10.8

/usr/lib/x86_64-linux-gnu似乎沒有符號鏈接/usr/lib/x86_64-linux-gnu/liblber.so,這是由相應的開發包提供的libldap2-dev

相關內容