c/c++ clang链接错误在Mac OSX - webkitgtk
c/c++ clang linking error on Mac OSX - webkitgtk
我正在尝试使用GTK3和WebKitGTK。我成功地运行了以下代码:
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#include <JavaScriptCore/JavaScript.h>
using namespace std;
static void destroyWindowCb(GtkWidget* widget, GtkWidget* window);
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);
int main(int argc, char* argv[])
{
// Initialize GTK+
gtk_init(&argc, &argv);
// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
// Create a browser instance
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
// Put the browser area into the main window
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
// Set up callbacks so that if either the main window or the browser instance is
// closed, the program will exit
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window);
// Load a web page into the browser instance
webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/");
// Make sure that when the browser area becomes visible, it will get mouse
// and keyboard events
gtk_widget_grab_focus(GTK_WIDGET(webView));
// Make sure the main window and all its contents are visible
gtk_widget_show_all(main_window);
// Run the main GTK+ event loop
gtk_main();
return 0;
}
static void
destroyWindowCb(GtkWidget* widget, GtkWidget* window)
{
gtk_main_quit();
}
static gboolean
closeWebViewCb(WebKitWebView* webView, GtkWidget* window)
{
gtk_widget_destroy(window);
return TRUE;
}
和下面的cmake列表:
cmake_minimum_required(VERSION 3.3)
project(HttpsMock)
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(WEBKIT REQUIRED webkitgtk-3.0)
# Setup CMake to use GTK+, tell the compiler where to look for headers
include_directories(${GTK3_INCLUDE_DIRS})
include_directories(${WEBKIT_INCLUDE_DIRS})
# and to the linker where to look for libraries
link_directories(${GTK3_LIBRARY_DIRS})
link_directories(${WEBKIT_LIBRARY_DIRS})
# Add other flags to the compiler
add_definitions(${GTK3_CFLAGS_OTHER})
add_definitions(${WEBKIT_CFLAGS_OTHER})
# Flags and source
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -v")
set(SOURCE_FILES main.cpp)
add_executable(HttpsMock ${SOURCE_FILES})
# Linking
target_link_libraries(HttpsMock ${GTK3_LIBRARIES})
target_link_libraries(HttpsMock ${WEBKIT_LIBRARIES})
但是一旦我尝试使用另一种方法,如:
WebKitURIRequest *request = webkit_uri_request_new("http://www.webkitgtk.org/");
程序不想再链接了。这真的很奇怪。下面是一个错误示例:
[100%] Linking CXX executable HttpsMock
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -o HttpsMock -L/opt/local/lib -search_paths_first -headerpad_max_install_names CMakeFiles/HttpsMock.dir/main.cpp.o -lwebkitgtk-3.0 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpangoft2-1.0 -lpango-1.0 -lm -lfontconfig -lfreetype -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lsoup-2.4 -lgio-2.0 -lgobject-2.0 -ljavascriptcoregtk-3.0 -lglib-2.0 -lintl -rpath /opt/local/lib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_webkit_uri_request_new", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
我真的不知道发生了什么事。谁能给我点化一下吗?谢谢
问题是我使用了pkg_check_modules(WEBKIT REQUIRED webkitgtk-3.0)
而不是pkg_check_modules(WEBKIT REQUIRED webkit2gtk-3.0)
相关文章:
- 各种版本的 Mac OSX 向后兼容性如何?(Xcode C++
- 如何在Mac OSX中获取真实的日历微秒时间(自1970年以来的纪元)?
- 如何在Mac OSX上的Qt中使用pkcs12 / pfx成功执行SSL加密?
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- std::<int>betterer() 比较器与 partial_copy_sort 的困难,在 Mac OSX 上"no matching function call.."
- Opencv 未定义的符号用于架构 cv:imwrite Mac osX high Sierra.
- Allegro 5.2 TTF 插件在 Mac OSX 版本中缺失
- 如何在Mac OSX C 中找到任何过程的PID
- 在Mac OSX中,文本的大小比使用Qt的Windows小。我希望到处都有相同的尺寸
- 如何在Mac OSX上的窗口客户端内获取真实的鼠标位置?
- 代码调用反向函数不会在Ubuntu 18上的G 或Clang 上编译,但神秘地在Mac OSX上使用
- Mac OSX Deprecated API - FSRef ref;
- 在 Mac OSX 上运行 Sublime Text 3 中的 C++
- 通过Qt(mac - OSX)进行的AWS查询没有得到任何结果
- C - 在Mac OSX上获取文件路径
- QT 5.2.1无法在Mac OSX 10.8.5上构建
- clang编译器在终端Mac OSX上不起作用
- 无法在Mac OSX 10.9.1上安装bitcoinjs服务器
- 使用SCON在Mac OSX 10.9上构建
- 避免在Mac OSX -reg中进行sigpipe