我正在尝试使用 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
。