【发布时间】:2009-11-28 01:53:32
【问题描述】:
我正在尝试创建一个使用 WebKit/GTK+ 中的一些代码的程序。具体来说,我想加载一个字符串,使用 WebKit 的解析器来构造一个 DOM 树,然后遍历该树。
我正在尝试使用一个名为 HTMLDocument 的类。 WebKit/GTK+ 没有将此作为其 API 的一部分公开,我在链接它时遇到了一些麻烦。
我能够正常构建 WebKit/GTK+,这给了我一个名为:libwebkit-1.0.so 的文件。我的程序是:
#include <iostream>
#include <WebCore/config.h>
#include <WebCore/html/HTMLDocument.h>
using namespace WebCore;
int main() {
String title = "test";
RefPtr<HTMLDocument> d = HTMLDocument::create(0);
d->open();
d->write("<!doctype html><html><head><title>" + title + "</title></head><body></body></html>");
}
这编译得很好(我正在使用与 webkit 相同的包含指令来构建),但会导致链接错误。
...test_doc.cpp:18: undefined reference to `WebCore::String::String(char const*)'
...test_doc.cpp:21: undefined reference to WebCore::Document::open(WebCore::Document*)'
...(similar for every function I use)
如果我跑:
nm -C .libs/libwebkit-1.0.so | grep 'WebCore::Document::open'
我明白了:
003b1830 T WebCore::Document::open(WebCore::Document*)
这似乎表明该功能可用。我有相当多的 C++ 经验,但在 Linux 下链接文件的经验不多。
我不希望这个确切的问题得到解决,但如果我有概念上的问题,我希望有人能纠正我。我的主要问题是为什么我在链接一个列出该函数已定义的 .so 文件时会看到“未定义的引用”错误。是否需要其他文件或构建步骤?
非常感谢。
使用: Ubuntu 9.10 g++ 4.4.1
g++ 被调用:
g++ --debug -DHAVE_CONFIG_H -I. `pkg-config --cflags libsoup-2.4` \
-DBUILDING_CAIRO__=1 -DBUILDING_GTK__=1 -DWTF_CHANGES -DWTF_USE_ICU_UNICODE=1 \
-DNDEBUG -I./WebCore -I./WebCore/accessibility -I./WebCore/bindings/js \
-I./WebCore/bridge -I./WebCore/bridge/c -I./WebCore/css -I./WebCore/dom \
...many more webkit include directories...
-DDATA_DIR=\"/usr/local/share\" \
test_doc.cpp -o test_doc.out \
./webkit-1.1.15.3/.libs/libwebkit-1.0.so
(我使用 -L/path/to/lib -lwebkit-1.0 得到相同的结果)
【问题讨论】:
-
你是如何调用链接器/编译器的?
-
我添加了 g++ 命令,虽然它相当混乱,因为我需要复制许多 webkit 选项才能成功构建它。谢谢!
-
实际上它看起来像“nm -D”(列出动态符号)没有给我想要的输出。
标签: c++ unix webkit g++ linker