0

As part of a project I'm working on, I need to make use of the WebKitGTK+ library. I downloaded the library (tarball) and compiled it as described here.

After the compilation was done:
The lib's headers are in /usr/local/include.
The lib's .so files are in /usr/local/lib.

In my C++ project I tried to add the following CMakeLists.txt file:

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})

However, when compiling the project I'm getting the following error:

[ 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

I have little-to-none experience with CMake and could really use some help.

iDaN5x
  • 616
  • 9
  • 12
  • Possible duplicate of [CMake link to external library](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) – Tsyvarev May 31 '17 at 16:37
  • Not a duplicate of that specific question. – andlabs May 31 '17 at 17:50
  • I agree that WebKitGTK+ has additional (and *preferrable*) way for link with. But it seems the question should be reworded, at least its title should contain name of the library. From the other side, `pkg_check_modules` approach is suitable for a lot of libraries, probably it should be noted in the answer to the duplicate question... – Tsyvarev Jun 01 '17 at 08:27

1 Answers1

2

You are trying to use WebKitGTK+, which is a separate library from both GTK+ and libsoup. You will need to duplicate your pkg_check_modules() code again for WebKitGTK+. You'll need to determine first if you are using WebKit1 or WebKit2 (they have subtly different APIs), and then find the appropriate pkg-config name for that version of WebKitGTK+; check the documentation and the contents of your /usr/lib/pkgconfig directory.

andlabs
  • 11,290
  • 1
  • 31
  • 52
  • The reason I'm not using `pkg_check_modules()` is that the library is locally compiled by me (and so located under `/usr/local/...`. I need a very specific (old) build of WebkitGTK+. SOUP and GTK are also needed (as separate libs) as WebkitGTK+ by itself is useless. – iDaN5x Jun 01 '17 at 08:50
  • Do note that the API is webkit2 – iDaN5x Jun 01 '17 at 08:56
  • Is this .lib file statically linked? If you want to do that, you may need to provide the WebKit2GTK+ binaries yourself too... You could ask the devs if static linking is possible as well. What is the problem with the newest versions of WebKit2GTK+? – andlabs Jun 01 '17 at 15:02