LIBADD不会在ubuntu上向另一个添加一个libtool库吗?

时间:2012-08-14 06:29:35

标签: 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.dylib在第二个变种的libtool:回声中出现。实际上,如果我在文字ubuntu命令中滑动等效参数,它就会成功完成。

缺少的参数对应LIBADD中的Makefile.am行。所以,问题是:我做得对吗?如果是这样,为什么它适用于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 <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.
$ 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 <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.
$ libtool --version
libtool (GNU libtool) 2.4.2
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 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.

1 个答案:

答案 0 :(得分:2)

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