Maed Hamed
Maed Hamed

Reputation: 11

How to link curl / curlpp to a CMake project?

I'm trying to build an obs-plugin, but I'm new to everything involved with it (c++, CMake, and the obs-plugin ecosystem). So, I tried to make my own based on the existing plugin https://github.com/royshil/obs-backgroundremoval

I made some string changes and built the plugin to test that everything is working before I started making code changes and all is good. But when I tried to link curlpp to send an HTTP request the plugin doesn't load anymore and I get the following error when the plugin tries to load in OBS:

os_dlopen(/home/user/.config/obs-studio/plugins/obs-backgroundremoval/bin/64bit/obs-backgroundremoval.so->/home/user/.config/obs-studio/plugins/obs-backgroundremoval/bin/64bit/obs-backgroundremoval.so): /home/user/.config/obs-studio/plugins/obs-backgroundremoval/bin/64bit/obs-backgroundremoval.so: undefined symbol: _ZNK6curlpp10OptionBaseltERKS0_

(the symbol is obfuscated for some reason, but if you remove the extra characters you can find it is curlpp::OptionBase)

After some research, I figured I need to link the library somehow, so I tried to do it similar to the way that the GitHub repo linked Onnxruntime.

external/FindCurlpp.cmake

find_path(Curlpp_INCLUDE_DIR
        NAMES
            "curlpp/cURLpp.hpp"
            "curlpp/Easy.hpp"
            "curlpp/Options.hpp"
            "curlpp/Exception.hpp"
        PATHS
            /usr/share/include ~/Downloads/curlpp-0.8.1/include
        DOC "Curlpp include directory")



include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LOGGING_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(Curlpp DEFAULT_MSG Curlpp_INCLUDE_DIR)

if (Curlpp_FOUND)
    set(Curlpp_INCLUDE_DIRS ${Curlpp_INCLUDE_DIR} CACHE STRING "Curlpp include directories")
    list(GET Curlpp_LIBRARIES 0 Curlpp_LIBRARY)
    get_filename_component(Curlpp_LIBRARY_DIR_EX ${Curlpp_LIBRARY} DIRECTORY)
    set(Curlpp_LIBRARY_DIR ${Curlpp_LIBRARY_DIR_EX} CACHE STRING "Curlpp library directory")
#else()
#    error("")
endif()

and in CMakeLists.txt I made the following changes:

find_package(CURL REQUIRED) # added

find_package(Curlpp REQUIRED) # added

find_package(Onnxruntime REQUIRED)

find_package(OpenCV 4.2 REQUIRED COMPONENTS core imgproc)

include_directories(
    ${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api
    ${LIBOBS_INCLUDE_DIR}
    ${LIBOBS_INCLUDE_DIRS}
    ${Curlpp_INCLUDE_DIRS} # added
    ${Onnxruntime_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
)

target_link_libraries(${CMAKE_PROJECT_NAME}
    ${LIBOBS_LIBRARIES}
    CURL::libcurl # added
    ${Onnxruntime_LIBRARIES}
    ${OpenCV_LIBRARIES}
)

But I still get the same error. Could you help me find what am I missing?

Upvotes: 1

Views: 607

Answers (0)

Related Questions