ubuntu - LIBADD 不会在 ubuntu 上将一个 libtool 库添加到另一个库吗?

标签 ubuntu autotools automake libtool

我有一个使用 GNU 自动工具的项目,其中 Makefile.am 的一部分如下所示:

lib_LTLIBRARIES += myproj/mysupport/libmysupport.la
myproj_mysupport_libmysupport_la_SOURCES = myproj/mysupport/some_sources.cc

lib_LTLIBRARIES += myproj/myapp/libmyapp.la
myproj_myapp_libmyapp_la_SOURCES = myproj/myapp/app_logic.cc
myproj_myapp_libmyapp_la_LIBADD = myproj/mysupport/libmysupport.la

sbin_PROGRAMS += myproj/myapp/myapp
myproj_myapp_myapp_SOURCES = myproj/myapp/main.cc
myproj_myapp_myapp_LDADD = myproj/myapp/libmyapp.la

这里,我有一个支持(libtool)库、一个应用程序库和一个二进制文件。应用程序库包含二进制文件 main 中的所有内容,这是二进制文件引入的唯一来源。

在我的 Mac 上,编译和链接都很好,一切都很好。然而,在 Ubuntu 上,我收到此链接错误:

/bin/bash ./libtool --tag=CXX   --mode=link g++ -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage --coverage -g -O0 -fprofile-arcs -ftest-coverage  -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib  -o myproj/myapp/myapp myproj/myapp/main.o myproj/myapp/libmyapp.la -lgcov -llog4cplus  -lboost_filesystem-mt -lboost_iostreams-mt -lboost_program_options-mt -lboost_system-mt -lboost_thread-mt -lboost_system-mt -pthread 
libtool: link: g++ -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage --coverage -g -O0 -fprofile-arcs -ftest-coverage -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -o myproj/myapp/.libs/myapp myproj/myapp/main.o -pthread  -L/usr/local/lib myproj/myapp/.libs/libmyapp.so -lgcov /usr/lib/liblog4cplus.so -lboost_filesystem-mt -lboost_iostreams-mt -lboost_program_options-mt -lboost_thread-mt -lboost_system-mt -pthread
/usr/bin/ld: myproj/myapp/main.o: undefined reference to symbol 'myproj::mysupport::Application::main(sauce::Modules&, int, char**)'
/usr/bin/ld: note: 'myproj::mysupport::Application::main(sauce::Modules&, int, char**)' is defined in DSO /home/user/code/local-myproj/debug/myproj/mysupport/.libs/libmysupport.so.0 so try adding it to the linker command line
/home/user/code/local-myproj/debug/myproj/mysupport/.libs/libmysupport.so.0: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

这是在我的 Mac 上运行的等效 libtool 命令:

/bin/sh ./libtool --tag=CXX   --mode=link g++-4.2 -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage --coverage -g -O0 -fprofile-arcs -ftest-coverage  -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib  -o myproj/myapp/myapp myproj/myapp/main.o myproj/myapp/libmyapp.la -lgcov -llog4cplus -L/usr/local/lib -lintl -R/usr/local/lib -Wl,-framework -Wl,CoreFoundation -lboost_filesystem-mt -lboost_iostreams-mt -lboost_program_options-mt -lboost_system-mt -lboost_thread-mt -lboost_system-mt
libtool: link: g++-4.2 -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage --coverage -g -O0 -fprofile-arcs -ftest-coverage -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -o myproj/myapp/.libs/myapp myproj/myapp/main.o -Wl,-framework -Wl,CoreFoundation -Wl,-bind_at_load  -L/usr/local/lib myproj/myapp/.libs/libmyapp.dylib /home/user/code/myproj/debug/myproj/mysupport/.libs/libmysupport.dylib -lgcov -llog4cplus -lintl -lboost_filesystem-mt -lboost_iostreams-mt -lboost_program_options-mt -lboost_thread-mt -lboost_system-mt

一个关键的区别似乎是 /home/user/code/myproj/debug/myproj/mysupport/.libs/libmysupport.dyliblibtool: 中的出现> 第二个变体的回声。事实上,如果我在 ubuntu 命令中插入等效参数,它就会成功完成。

缺少的参数对应于 Makefile.am 中的 LIBADD 行。那么问题来了:我这样做对吗?如果是这样,为什么它可以在 OS X 上运行,而不能在 Ubuntu 上运行?

OS X 上的一些相关版本:

$ autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.
$ automake --version
automake (GNU automake) 1.12.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96e2e4f9fbf3efd6e4f3f2fef7e2b8f5f9fb" rel="noreferrer noopener nofollow">[email protected]</a>>
       and Alexandre Duret-Lutz <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="19787d75597e776c37766b7e" rel="noreferrer noopener nofollow">[email protected]</a>>.
$ libtool -V
Apple Inc. version cctools-822
$ g++-4.2 --version
i686-apple-darwin11-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

现在在 Ubuntu 上:

$ autoconf --version
autoconf (GNU Autoconf) 2.68
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.
$ automake --version
automake (GNU automake) 1.11.3
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5a1a7bab8b0ac95a7b0b1bdb4a1fbb6bab8" rel="noreferrer noopener nofollow">[email protected]</a>>
       and Alexandre Duret-Lutz <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c5c0c8e4c3cad18acbd6c3" rel="noreferrer noopener nofollow">[email protected]</a>>.
$ libtool --version
libtool (GNU libtool) 2.4.2
Written by Gordon Matzigkeit <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbbcb4a9bf9bbcb5aef5bab2f5b6b2aff5bebfae" rel="noreferrer noopener nofollow">[email protected]</a>>, 1996

Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

最佳答案

您真的需要安装支持库吗?因为您可以尝试在 noinst_LTLIBRARIES 中声明它,看看是否有效。

关于ubuntu - LIBADD 不会在 ubuntu 上将一个 libtool 库添加到另一个库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11946876/

相关文章:

linux - 在 Linux 中删除文件名的 10 个字符

gdb - 使用 libtool 和 gdb

c++ - 如何交叉编译具有依赖项的 C++ 库?

c++ - 在单独的 'build' 目录中使用 autotools build system/Building

python-2.7 - 无法在 Spyder 2.2.5 (Ubuntu 14.04) 中打开 Python 解释器

linux - 如何在 fstab 文件中使用 mount 命令

python - SSL v2 undefined symbol 、Manjaro 和 Ubuntu

c++ - 如何在 C++ Autotools 项目中禁用 C 编译器

c++ - GNU 自动工具 : Debug/Release targets?

c++ - 如何为 CxxTest 编写 automake 文件?