【问题标题】:Linking G729 library (Library exists and symbols too)链接 G729 库(库存在且符号也存在)
【发布时间】:2017-12-04 15:40:23
【问题描述】:

我目前正在努力链接一个简单的库。

我从这里Belledonne G729 成功编译并安装了 G729 实现,如下所示:

cmake . -DCMAKE_INSTALL_PREFIX=/usr    
make
make install

当我检查符号是否存在时:

nm /usr/lib64/libbcg729.so | less
....
0000000000001fb8 T _init
000000000000de40 T initBcg729CNGChannel
00000000000046dd T initBcg729DecoderChannel
000000000000f5c6 T initBcg729DTXChannel
0000000000005353 T initBcg729EncoderChannel
0000000000010107 T initBcg729VADChannel
....

但是当我尝试编译这个简单的 main.cpp 时:

#include <bcg729/decoder.h>             // for bcg729DecoderChannelContextStruct


int main()
{
    bcg729DecoderChannelContextStruct* decoderChannelContext = initBcg729DecoderChannel();

    return 0;
}

我得到这个结果:

c++ -v main.o -o main -lbcg729

Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'main' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. main.o -lbcg729 -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
main.o: In function `main':
/opt/cppplayground/main.cpp:39: undefined reference to `initBcg729DecoderChannel()'
collect2: error: ld returned 1 exit status

我不知道问题出在哪里,因为如果找不到该库,链接器会抱怨它不存在。但在这种情况下,库存在,我想使用的功能也存在。

如果有人能帮忙就好了;)

提前致谢!

【问题讨论】:

  • 你在sudo ldconfig -v的输出中看到你的库了吗?
  • 是的,否则我会收到类似“找不到 libbcg729.so.0”的错误

标签: c++ linker-errors centos7 g729


【解决方案1】:

找到了.... 因为它是一个 C 库,所以我忘记在包含项周围添加“extern "C" {}'。

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    • 2021-04-15
    • 2023-01-09
    相关资源
    最近更新 更多