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) ライブラリ、アプリケーション ライブラリ、およびバイナリがあります。アプリケーション ライブラリには、バイナリmain
によって持ち込まれる唯一のソースであるバイナリ save にすべてが含まれています。
私の 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
主な違いは、2 番目の亜種のlibtool:
エコーでのの出現です。実際、文字通りの ubuntu コマンドで同等の引数を差し込むと、正常に完了します。
不足している引数は、 のLIBADD
行に対応していMakefile.am
ます。だから、質問:私はこれを正しくやっていますか?もしそうなら、なぜそれは Ubuntu ではなく OS X で動作するのですか?
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.