簡體   English   中英

為什么gcc鏈接器看不到我的析構函數?

[英]Why gcc linker does not see my destructor?

我正在嘗試按照https://code.google.com/p/wkhtmltopdf/wiki/compilation中的說明在Linux機器上編譯wkhtmltopdf-qt。

現在我被鏈接器拒之門外。 它顯示了幾個錯誤,但引起我注意的一個錯誤是:

/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a(AccessibilityRenderObject.o): In function `WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()':
AccessibilityRenderObject.cpp:(.text._ZN7WebCore25AccessibilityRenderObjectD0Ev+0x5): undefined reference to `WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()'

至少可以說這很奇怪。 首先,因為鏈接器聲稱析構函數嘗試引用自身,其次,因為它沒有這樣做! 瘋狂的東西...無論如何,一切似乎都已定義。 請注意:

ubuntu@ip-10-245-78-162:~$ nm --defined-only -C -A /home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a | grep ~AccessibilityRenderObject
/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a:AccessibilityRenderObject.o:0000000000000000 T WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()
/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a:AccessibilityRenderObject.o:0000000000000000 T WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()
/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a:AccessibilityRenderObject.o:0000000000000000 T WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()
ubuntu@ip-10-245-78-162:~/wkhtmltopdf-qt/src/3rdparty/webkit/Source/WebCore/accessibility$

接下來,在文件AccessibilityRenderObject.cpp中:

#include <wtf/unicode/CharacterNames.h>

using namespace std;

namespace WebCore {

using namespace HTMLNames;

AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer)
    : AccessibilityObject()
    , m_renderer(renderer)
    , m_ariaRole(UnknownRole)
    , m_childrenDirty(false)
    , m_roleForMSAA(UnknownRole)
{
    m_role = determineAccessibilityRole();

#ifndef NDEBUG
    m_renderer->setHasAXObject(true);
#endif
}

AccessibilityRenderObject::~AccessibilityRenderObject()
{
    ASSERT(isDetached());
}

因此,析構函數的定義就很好。 但我走得更遠-我再次編譯了AccessibilityRenderObject.cpp,這次在預處理器處停止。 當然,析構函數在那里:

class AccessibilityRenderObject : public AccessibilityObject {
protected:
    AccessibilityRenderObject(RenderObject*);
public:
    static PassRefPtr<AccessibilityRenderObject> create(RenderObject*);
    virtual ~AccessibilityRenderObject();
.
.
.
AccessibilityRenderObject::~AccessibilityRenderObject()
{
    ((void)0);
}

用於編譯該文件(以及許多其他文件)的編譯行是這樣的:

g++ -c -m64 -pipe -Wall -Wextra -Wreturn-type -fno-strict-aliasing -Wcast-align -Wchar-subscripts -Wformat-security -Wreturn-type -Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-switch-enum -Wundef -Wmissing-noreturn -Winit-self -Wno-c++0x-compat -ffunction-sections -fdata-sections -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -DNDEBUG -DBUILDING_QT__=1 -DNDEBUG -DQT_ASCII_CAST_WARNINGS -DENABLE_XSLT=0 -DENABLE_WEB_TIMING=0 -DENABLE_JAVASCRIPT_DEBUGGER=1 -DENABLE_DATABASE=1 -DENABLE_EVENTSOURCE=1 -DENABLE_OFFLINE_WEB_APPLICATIONS=1 -DENABLE_DOM_STORAGE=1 -DENABLE_ICONDATABASE=1 -DENABLE_CHANNEL_MESSAGING=1 -DENABLE_DIRECTORY_UPLOAD=0 -DENABLE_FILE_SYSTEM=0 -DENABLE_QUOTA=0 -DENABLE_SQLITE=1 -DENABLE_DASHBOARD_SUPPORT=0 -DENABLE_FILTERS=1 -DENABLE_XPATH=1 -DENABLE_WCSS=0 -DENABLE_SHARED_WORKERS=1 -DENABLE_WORKERS=1 -DENABLE_XHTMLMP=0 -DENABLE_DETAILS=1 -DENABLE_METER_TAG=1 -DENABLE_PROGRESS_TAG=1 -DENABLE_BLOB=1 -DENABLE_NOTIFICATIONS=1 -DENABLE_INPUT_SPEECH=0 -DENABLE_INSPECTOR=1 -DENABLE_3D_RENDERING=1 -DENABLE_WEB_AUDIO=0 -DENABLE_WEBGL=0 -DENABLE_MEDIA_STATISTICS=0 -DENABLE_VIDEO_TRACK=0 -DENABLE_TOUCH_ICON_LOADING=0 -DENABLE_ANIMATION_API=0 -DENABLE_SVG=1 -DENABLE_SVG_FONTS=1 -DENABLE_SVG_FOREIGN_OBJECT=1 -DENABLE_SVG_ANIMATION=1 -DENABLE_SVG_AS_IMAGE=1 -DENABLE_SVG_USE=1 -DENABLE_DATALIST=1 -DENABLE_TILED_BACKING_STORE=1 -DENABLE_NETSCAPE_PLUGIN_API=1 -DENABLE_WEB_SOCKETS=1 -DWTF_USE_QT_BEARER=1 -DENABLE_TOUCH_EVENTS=1 -DENABLE_VIDEO=0 -DENABLE_VIDEO=0 -DSQLITE_CORE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_COMPLETE -DXP_UNIX -DENABLE_NETSCAPE_PLUGIN_METADATA_CACHE=1 -DBUILDING_JavaScriptCore -DBUILDING_WTF -DBUILDING_WEBKIT -DQT_MAKEDLL -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../../../../mkspecs/linux-g++-64 -I. -I../../../../../include/QtCore -I../../../../../include/QtNetwork -I../../../../../include/QtGui -I../../../../../include -I../JavaScriptCore -I../../Source -I../ThirdParty -I../JavaScriptCore/assembler -I../JavaScriptCore/bytecode -I../JavaScriptCore/bytecompiler -I../JavaScriptCore/heap -I../JavaScriptCore/dfg -I../JavaScriptCore/debugger -I../JavaScriptCore/interpreter -I../JavaScriptCore/jit -I../JavaScriptCore/parser -I../JavaScriptCore/profiler -I../JavaScriptCore/runtime -I../JavaScriptCore/wtf -I../JavaScriptCore/wtf/gobject -I/home/ubuntu/wkhtmltopdf-qt/src/3rdparty/webkit/Source/JavaScriptCore/wtf/symbian -I../JavaScriptCore/wtf/unicode -I../JavaScriptCore/yarr -I../JavaScriptCore/API -I../JavaScriptCore/ForwardingHeaders -I../JavaScriptCore/generated -Ibridge/qt -Ipage/qt -Iplatform/graphics/qt -Iplatform/network/qt -Iplatform/qt -I../WebKit/qt/Api -I../WebKit/qt/WebCoreSupport -I. -Iaccessibility -Ibindings -Ibindings/generic -Ibridge -Icss -Idom -Idom/default -Iediting -Ifileapi -Ihistory -Ihtml -Ihtml/canvas -Ihtml/parser -Ihtml/shadow -Iinspector -Iloader -Iloader/appcache -Iloader/archive -Iloader/cache -Iloader/icon -Imathml -Inotifications -Ipage -Ipage/animation -Iplatform -Iplatform/animation -Iplatform/audio -Iplatform/graphics -Iplatform/graphics/filters -Iplatform/graphics/filters/arm -Iplatform/graphics/texmap -Iplatform/graphics/transforms -Iplatform/image-decoders -Iplatform/leveldb -Iplatform/mock -Iplatform/network -Iplatform/sql -Iplatform/text -Iplatform/text/transcoder -Iplugins -Irendering -Irendering/mathml -Irendering/style -Irendering/svg -Istorage -Isvg -Isvg/animation -Isvg/graphics -Isvg/graphics/filters -Isvg/properties -Itesting -Iwebaudio -Iwebsockets -I/home/ubuntu/wkhtmltopdf-qt/src/3rdparty/webkit/Source/WebCore/wml -Iworkers -Ixml -Ibridge/jsc -Ibindings/js -I/home/ubuntu/wkhtmltopdf-qt/src/3rdparty/webkit/Source/WebCore/bindings/js/specialization -Ibridge/c -Itesting/js -Igenerated -I../../Source -I../../include -I../include/QtWebKit -I../include -I../../../sqlite -I/usr/X11R6/include -I.moc/release-static -o .obj/release-static/AccessibilityRenderObject.o accessibility/AccessibilityRenderObject.cpp

最后,失敗的鏈接器命令行是這樣的:

g++ -Wl,-rpath-link,/home/ubuntu/wkhtmltopdf-qt/lib -m64 -Wl,-O1 -Wl,-rpath,/home/ubuntu/wkhtmltopdf-qt/src/3rdparty/webkit/Source/lib -Wl,-rpa
th,/home/ubuntu/wkqt/lib -Wl,-rpath,/home/ubuntu/wkqt/lib -o tst_qwebframe .obj/release-static/tst_qwebframe.o .obj/release-static/qrc_tst_qweb
frame.o    -L/home/ubuntu/wkhtmltopdf-qt/lib -L/usr/X11R6/lib64 -L/home/ubuntu/wkhtmltopdf-qt/lib -lQtWebKit -L../../WebCore/release -L../../Ja
vaScriptCore/release -L/usr/X11R6/lib64 -Wl,--start-group -lwebcore -lQtWebKit -Wl,--end-group -ljscore -lQtTest -lQtGui -lXrender -lXext -lX11
 -lQtNetwork -lQtCore -lm -ldl -lrt -lpthread -lXrender -lXext -lX11 -lm

並且所有涉及上述析構函數的鏈接器錯誤均為:

/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a(AccessibilityRenderObject.o): In function `WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()':
AccessibilityRenderObject.cpp:(.text._ZN7WebCore25AccessibilityRenderObjectD2Ev+0x3): undefined reference to `vtable for WebCore::AccessibilityRenderObject'
/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a(AccessibilityRenderObject.o): In function `WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()':
AccessibilityRenderObject.cpp:(.text._ZN7WebCore25AccessibilityRenderObjectD0Ev+0x5): undefined reference to `WebCore::AccessibilityRenderObject::~AccessibilityRenderObject()'

有許多可疑的鏈接器錯誤,例如:

/home/ubuntu/wkhtmltopdf-qt/lib/libwebcore.a(AccessibilityMenuList.o):(.data.rel.ro._ZTIN7WebCore21AccessibilityMenuListE[typeinfo for WebCore:
:AccessibilityMenuList]+0x10): undefined reference to `typeinfo for WebCore::AccessibilityRenderObject'

但是據我所知,所有虛函數均已正確聲明和定義,並且在所有源代碼樹中沒有任何makefile提及rtti

誰能告訴我發生了什么事?

編譯命令包括以下選項: -ffunction-sections -fdata-sections在此處記錄 )。 -ffunction-sections將每個函數放在目標文件的自己的節中,而不是簡單地將所有函數放在單個.text節中。 同樣, -fdata-sections適用於全局/靜態數據。

這個想法是,通過指定--gc-sections未使用的輸入節的垃圾回收 ),鏈接器可以在將“ unreachable”節合並到二進制文件的最終.text節之前將其丟棄。 簡而言之,在不為每個功能使用單獨的編譯單元的情況下減小代碼大小。

這就是預感。 我希望它在沒有--gc-sections選項的情況下--gc-sections正常工作。 顯然沒有好處,因為什么都不會被丟棄。 為什么會失敗?

當實現析構函數時,gcc,clang等使用的C ++ ABI通常會生成3個析構變量,以D0EvD1EvD2Ev以及該類的vtabletypeinfo數據typeinfo 我的猜測是這些單獨的部分未正確合並。 我不知道這是錯誤還是鏈接程序(或鏈接規范)的限制。


在構建共享庫時,這也是沒有用的,因為無法預先知道將使用哪些符號。 -fPIC調用編譯器,應該可以,因為對象只是被歸檔了。 但是, -fvisibility選項可能會使問題復雜化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM