1. 鏈接靜態庫的順序
在鏈接靜態庫時,如果多個靜態庫之間存在依賴關系,則有依賴關系的靜態庫之間存在鏈接順序問題。這在使用靜態庫時需要注意,否則會報符號找不到的鏈接錯誤。
例如:
lib2.a 依賴於 lib1.a,而最終可執行文件 test 依賴於 lib2.a,則鏈接選項應為:
-llib2.a -llib1.a,而不能反過來,否則會報 lib1.a 中的某些符號未定義。
2. 編譯時遇到 undefined references to static stl 的情況 具體log:
undefined reference to `std::__detail::_List_node_base::_M_unhook()'
/home/sonic/workplace/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1532: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
/home/sonic/workplace/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1532: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
/home/sonic/workplace/project/android_webdemo/jni/webdemo/../Library/libs/poco/1.5.1/Android/libPocoXML.a(AbstractNode.o): In function `std::list<Poco::XML::DOMObject*, std::allocator<Poco::XML::DOMObject*> >::_M_insert(std::_List_iterator<Poco::XML::DOMObject*>, Poco::XML::DOMObject* const&)':
/home/sonic/workplace/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1516: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/home/sonic/workplace/project/android_webdemo/jni/webdemo/../Library/libs/poco/1.5.1/Android/libPocoXML.a(ElementsByTagNameList.o): In function `std::list<Poco::XML::DOMObject*, std::allocator<Poco::XML::DOMObject*> >::_M_insert(std::_List_iterator<Poco::XML::DOMObject*>, Poco::XML::DOMObject* const&)':
/home/sonic/workplace/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1516: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/home/sonic/workplace/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1516: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/home/sonic/workplace/project/android_webdemo/jni/webdemo//libFS.a(FsString.o): In function `FS::int2string(int)':
FsString.cpp:(.text+0xfc): undefined reference to `std::allocator<char>::allocator()'
FsString.cpp:(.text+0x120): undefined reference to `std::allocator<char>::~allocator()'
FsString.cpp:(.text+0x13c): undefined reference to `std::allocator<char>::~allocator()'
/home/sonic/workplace/project/android_webdemo/jni/webdemo//libFS.a(FsString.o): In function `FS::int2wstring(int)':
FsString.cpp:(.text+0x1a8): undefined reference to `std::allocator<char>::allocator()'
FsString.cpp:(.text+0x1d0): undefined reference to `std::allocator<char>::~allocator()'
FsString.cpp:(.text+0x228): undefined reference to `std::allocator<char>::~allocator()'
/home/sonic/workplace/project/android_webdemo/jni/webdemo//libFS.a(FsString.o): In function `FS::wstring2string(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
FsString.cpp:(.text+0x2f8): undefined reference to `std::allocator<char>::allocator()'
FsString.cpp:(.text+0x318): undefined reference to `std::allocator<char>::~allocator()'
FsString.cpp:(.text+0x348): undefined reference to `std::allocator<char>::~allocator()'
/home/sonic/workplace/project/android_webdemo/jni/webdemo//libFS.a(FsString.o): In function `FS::string2wstring(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
FsString.cpp:(.text+0x3f8): undefined reference to `std::allocator<wchar_t>::allocator()'
FsString.cpp:(.text+0x418): undefined reference to `std::allocator<wchar_t>::~allocator()'
FsString.cpp:(.text+0x448): undefined reference to `std::allocator<wchar_t>::~allocator()'
等等.
用的ndk gnustl_static 。 google 了一下,在 https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/FslGMERCvl0 發現了大牛的回答.
1/ Don't add -lstdc++
