LIBADD не будет добавлять одну библиотеку libtool в другую на ubuntu?
У меня есть проект, использующий 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
Вот эквивалентная команда libtool, выполняемая на мой mac:
/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:
Эхо 2-го варианта. Действительно, если я проскальзываю эквивалентный аргумент в буквальной команде 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.