2

我有一个使用 GNU autotools 的项目,其中一部分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)库、一个应用程序库和一个二进制文件。应用程序库包含二进制文件 save 中的所有内容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 命令中添加了等价的参数,它就会成功完成。

缺少的参数对应LIBADDMakefile.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.
4

1 回答 1

2

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

于 2012-08-14T07:05:47.023 回答