【问题标题】:Linking error : undefined reference to `avahi_alternative_service_name'链接错误:未定义对“avahi_alternative_service_name”的引用
【发布时间】:2012-10-03 15:52:50
【问题描述】:

知道我需要在库中找到此符号。我正在尝试编译基于 avahi 的测试代码以查看服务。但我收到undefined reference toavahi_alternative_service_name'`.. 我不知道哪个库包含这个,我正在运行 UBUNTU 12.04。我尝试安装几个软件包但没有成功..任何想法 谢谢。。

我安装了以下软件包

dpkg --get-selections | grep avahi
avahi-autoipd                   install
avahi-daemon                    install
avahi-utils                     install
libavahi-cil-dev                install
libavahi-client-dev             install
libavahi-client3                install
libavahi-client3:i386           install
libavahi-common-data            install
libavahi-common-data:i386       install
libavahi-common-dev             install
libavahi-common3                install
libavahi-common3:i386           install
libavahi-core7                  install
libavahi-glib-dev               install
libavahi-glib1                  install
libavahi-gobject0               install
libavahi-ui-dev                 install
libavahi-ui-gtk3-0              install
libavahi-ui0                    install
libavahi1.0-cil                 install

命令
gcc -fpermissive testAvahi.c -o testAvahi

【问题讨论】:

  • 你是如何编译你的代码的?
  • 显示用于编译/链接的命令行——它可能就像在错误的地方指定库一样简单(它需要在任何依赖它的对象或库之后)。跨度>
  • @twid,因此您没有将编译的对象链接到任何库。做gcc -o testAvahi testAvahi.c -l <avahi library>。检查 girish 的答案以找出哪个 avahi 库提供了所需的名称。例如,如果是 libXYZ.a,您的命令应如下所示:gcc -o testAvahi testAvahi.c -l XYZ。

标签: c++ ubuntu-12.04 avahi


【解决方案1】:

实际上需要定位库,然后需要将它们传递给链接器,所以下面的命令确实对我有用

gcc -fpermissive testAvahi.c -o testAvahi -L/usr/lib/x86_64-linux-gnu/ -lavahi-client -lavahi-common

【讨论】:

    【解决方案2】:

    如果您有一个放置 c++ 库的公共文件夹,您可以使用 nm 命令检查函数的搜索 像

    cd /usr/lib
    

    nm -AC * | grep avahi_alternative_service_name

    binutils 中提供了 nm 实用程序(sudo apt-get install binutils)

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 2014-01-09
      • 2022-01-01
      • 2017-05-02
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多