简体   繁体   English

Autotools项目中的未定义引用

[英]Undefined references in autotools project

Here's the project I'm developing: https://github.com/bigdatadev/riemannpp 这是我正在开发的项目: https : //github.com/bigdatadev/riemannpp

I'm a relative beginner to autotools, and I'm having difficulty getting my shared object riemannpp to link against another library called riemann-client (link in the README.md). 我是一个相对的初学者自动工具,而且我没法把我的共享对象riemannpp反对另一个名为链接库riemann-client (在README.md链接)。

I find the compile / link flags for riemann-client using PKG_CHECK_MODULES in configure.ac (ln. 38). 我在configure.ac(第38页)中使用PKG_CHECK_MODULES找到riemann-client的编译/链接标志。 I then use the flags in Makefile.am when I build the .so using LIBADD (ln. 29). 然后,当我使用LIBADD(第29页)构建.so时,会在Makefile.am中使用这些标志。

If you try to compile the sources ( make ), libriemannpp.so will build, but seems that I am doing something very wrong when I try to link the client and unit tests. 如果您尝试编译源代码( make ),则会构建libriemannpp.so,但是当我尝试链接客户端测试和单元测试时,似乎做错了什么。 I add the reference to libriemannpp.so by referencing libriemannpp.la (Makefile.am ln. 41). 我通过引用libriemannpp.la(Makefile.am ln。41)将引用添加到libriemannpp.so。

The error I'm getting is undefined references to functions from the riemann-client library which riemannpp.so depends. 我收到的错误是riemannpp.so所依赖的riemann-client库中对函数的未定义引用。 nm shows that riemannpp.so has undefined references, but ldd shows no dependency on riemann-client, which nm shows does exports the missing symbols. nm显示riemannpp.so具有未定义的引用,但是ldd显示不依赖riemann-client,nm显示确实输出丢失的符号。 I have tried fiddling with the Makefile.am to get the riemannpp library to link properly, but I'm giving in and am hoping an expert will be able to help me out. 我尝试摆弄Makefile.am以使riemannpp库正确链接,但是我屈服了,希望专家能够帮助我。

If anyone can help me understand what I'm doing wrong and how to fix it I would be very grateful. 如果有人能帮助我了解我在做什么以及如何解决,我将非常感谢。

I'm using Ubuntu 14.04 with default system packages for gcc, autoconf, automake and libtool. 我将Ubuntu 14.04与gcc,autoconf,automake和libtool的默认系统软件包一起使用。


EDIT: Some more information 编辑:更多信息

ldd output on libriemannpp.so: 在libriemannpp.so上的ldd输出:

  • linux-vdso.so.1 => (0x00007fff36b29000) linux-vdso.so.1 =>(0x00007fff36b29000)
  • libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9b13f54000) libstdc ++。so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6(0x00007f9b13f54000)
  • libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9b13b8e000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6(0x00007f9b13b8e000)
  • libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9b13977000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1(0x00007f9b13977000)
  • libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9b13671000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6(0x00007f9b13671000)
  • /lib64/ld-linux-x86-64.so.2 (0x00007f9b14488000) /lib64/ld-linux-x86-64.so.2(0x00007f9b14488000)

nm output on libriemannpp.so: nm在libriemannpp.so上的输出:

  • U _Z17riemann_event_newv U _Z17riemann_event_newv
  • U _Z17riemann_event_setP6_Eventz U _Z17riemann_event_setP6_Eventz
  • U _Z17riemann_query_newPKc U _Z17riemann_query_newPKc
  • U _Z18riemann_client_newv U _Z18riemann_client_newv
  • U _Z18riemann_event_freeP6_Event U _Z18riemann_event_freeP6_Event
  • U _Z18riemann_query_freeP6_Query U _Z18riemann_query_freeP6_Query
  • ... etc ... ...等等...

nm output on libriemann-client.so: nm在libriemann-client.so上的输出:

  • 0000000000002c70 T riemann_event_attribute_add 0000000000002c70 T riemann_event_attribute_add
  • 0000000000002cd0 T riemann_event_create 0000000000002cd0 T riemann_event_create
  • 0000000000002610 T riemann_event_free 0000000000002610 T riemann_event_free
  • 00000000000025f0 T riemann_event_new 00000000000025f0 T riemann_event_new
  • ... etc ... ...等等...

So it seems that the symbols are correctly defined in libriemann-client.so. 因此,似乎这些符号已在libriemann-client.so中正确定义。 At least I'm not going completely insane... 至少我不会完全发疯...

The offending build output: 令人反感的构建输出:

/bin/bash ./libtool  --tag=CXX   --mode=link g++  -g -O2 -std=c++11   -o src/client/riemannpp src/client/riemannpp.o ./src/riemannpp/libriemannpp.la -L/usr/local/lib -lriemann-client    
libtool: link: g++ -g -O2 -std=c++11 -o src/client/.libs/riemannpp src/client/riemannpp.o  ./src/riemannpp/.libs/libriemannpp.so -L/usr/local/lib /usr/local/lib/libriemann-client.so
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_send_message(_riemann_client_t*, _Msg*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_query_set_string(_Query*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_send_message_oneshot(_riemann_client_t*, _Msg*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_disconnect(_riemann_client_t*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_set(_Attribute*, char const*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_new()'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_free(_Attribute*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_event_new()'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_free(_riemann_client_t*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_query_new(char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_create(char const*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_message_set_query(_Msg*, _Query*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_event_set(_Event*, ...)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_query_free(_Query*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_event_attribute_add(_Event*, _Attribute*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_set_value(_Attribute*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_new()'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_message_new()'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_connect(_riemann_client_t*, riemann_client_type_t, char const*, int)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_event_tag_add(_Event*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_message_free(_Msg*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_attribute_set_key(_Attribute*, char const*)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_message_set_events_n(_Msg*, unsigned long, _Event**)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_client_create(riemann_client_type_t, char const*, int)'
./src/riemannpp/.libs/libriemannpp.so: undefined reference to `riemann_event_free(_Event*)'

Steps to try it out: 尝试步骤:

$ git clone git@github.com:algernon/riemann-c-client.git
$ cd riemann-c-client
$ sudo apt-get install protobuf-c-compiler # ubuntu
$ ./configure && make && sudo make install
$ cd ..
$ git clone git@github.com:bigdatadev/riemannpp.git
$ cd riemannpp
$ ./autogen.sh
$ ./configure && make

Note that you will have unresolved symbol references in libriemannpp.so when compiling the client program, despite libriemannpp having references to the riemann-c-client (obtained via pkg-config riemann-client --cflags --libs ). 请注意,尽管libriemannpp引用了riemann-c-client(通过pkg-config riemann-client --cflags --libs ),但在编译客户端程序时,libriemannpp.so中仍存在未解析的符号引用。


EDIT: I get the same problem even if I run ./configure --disable-shared , which seems to rule out any possibility of a bug in the shared object I'm building. 编辑:即使我运行./configure --disable-shared ,我也会遇到相同的问题,这似乎排除了我正在构建的共享库中任何错误的可能性。 I'm clearly missing how to add the dependency information to the library, but Google isn't giving any answers away. 我显然不知道如何将依赖项信息添加到库中,但是Google并未给出任何答案。

It seems very unlikely that this is a bug in the riemann-client library, as that builds and passes its unit tests flawlessly. 这似乎不太可能是riemann-client库中的错误,因为它可以完美地构建并通过其单元测试。

riemann-client fails to use riemann-client无法使用

#ifdef __cplusplus
extern "C" {
#endif
   ...
#ifdef __cplusplus
}
#endif

in its header files, therefore your riemanpp code parts think it is calling C++ code when in fact it is C. And you cannot just use 在其头文件中,因此您的riemanpp代码部分认为它实际上是C时正在调用C ++代码。您不能只使用

#ifdef __cplusplus
extern "C" {
#endif
#include <riemann/event.h>
...

as that could possibly subject C++ headers to be wrongly wrapped into C calling conventions. 因为那样可能会使C ++标头错误地包装到C调用约定中。 (Meaning the fix must occur in riemann-client) (意味着该修复程序必须在riemann-client中发生)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM