Can't add locally compiled library to CMake project

531 Views Asked by At

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.

1

There are 1 best solutions below

3
On

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.