0

作为我正在进行的项目的一部分,我需要使用 WebKitGTK+ 库。我下载了库(tarball)并按照此处所述进行了编译。

编译完成后:
lib 的头文件在/usr/local/include.
lib 的.so文件位于/usr/local/lib.

在我的 C++ 项目中,我尝试添加以下CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.7)
project(CVE_2016_4657)

set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(CVE_2016_4657 ${SOURCE_FILES})

find_package(PkgConfig REQUIRED)

include_directories(/usr/local/include/webkitgtk-4.0)
link_directories(/usr/local/lib/webkit2gtk-4.0)

pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})

pkg_check_modules(SOUP REQUIRED libsoup-2.4)
include_directories(${SOUP_INCLUDE_DIRS})
link_directories(${SOUP_LIBRARY_DIRS})
add_definitions(${SOUP_CFLAGS_OTHER})

target_link_libraries(
        CVE_2016_4657
        ${GTK3_LIBRARIES}
        ${SOUP_LIBRARIES})

但是,在编译项目时出现以下错误:

[ 50%] Linking CXX executable CVE_2016_4657
CMakeFiles/CVE_2016_4657.dir/main.cpp.o: In function `main':
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to 
`webkit_web_view_get_type'
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to 
`webkit_web_view_new'
/home/idanas/CLionProjects/Switcheroo/main.cpp:29: undefined reference to 
`webkit_web_view_load_uri'
collect2: error: ld returned 1 exit status
CMakeFiles/CVE_2016_4657.dir/build.make:94: recipe for target 
'CVE_2016_4657' failed
make[3]: *** [CVE_2016_4657] Error 1
CMakeFiles/Makefile2:67: recipe for target 
'CMakeFiles/CVE_2016_4657.dir/all' failed
make[2]: *** [CMakeFiles/CVE_2016_4657.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 
'CMakeFiles/CVE_2016_4657.dir/rule' failed
make[1]: *** [CMakeFiles/CVE_2016_4657.dir/rule] Error 2
Makefile:118: recipe for target 'CVE_2016_4657' failed
make: *** [CVE_2016_4657] Error 2

我对 CMake 几乎没有经验,并且真的可以使用一些帮助。

4

1 回答 1

2

您正在尝试使用 WebKitGTK+,它是一个独立于 GTK+ 和 libsoup 的库。您将需要pkg_check_modules()再次为 WebKitGTK+ 复制代码。您需要首先确定您使用的是 WebKit1 还是 WebKit2(它们的 API 略有不同),然后为该版本的 WebKitGTK+ 找到适当的 pkg-config 名称;检查文档和/usr/lib/pkgconfig目录的内容。

于 2017-05-31T17:53:34.840 回答