Does CMake support linking multiple third party libraries?

Hi all! This is a question I have also posted on Stackoverflow which has left me rather confused and head scratching.

I am using CMake to define the compilation of a C++ executable. The goal is to use 2 third-party libraries, Open3D and OpenCV. I am able to include one of the two with target_link_libraries, but including both results in OpenCV functions not being found.

This is my current CMakeLists.txt

minimum_required(VERSION 3.20)

find_package(Open3D REQUIRED)
find_package(OpenCV REQUIRED)

add_executable(ORB_SLAM src/main.cpp)

#target_link_libraries(ORB_SLAM ${Open3D_LIBRARIES})
target_link_libraries(ORB_SLAM ${OpenCV_LIBS})

# When printed, ${Open3D_LIBRARIES} = Open3D::Open3D
#               ${OpenCV_LIBS} = opencv_calib3d;opencv_core;...many more..;opencv_xphoto

With this CMakeList.txt, I can successfully use OpenCV functions. By using the commented out Open3D target_link_libraries, I can successfully use Open3D. When uncommenting both target_link_libraries, it fails to find OpenCV functionality, regardless of the order of the find_package and target_link_libraries. The same error even occurs if I include both in a single target_link_libraries(ORB_SLAM ${OpenCV_LIBS} ${Open3D_LIBRARIES}). The same error occurs for CMake 3.16.3 and 3.21.3.

The error is as follows:

/usr/bin/ld: CMakeFiles/ORB_SLAM.dir/src/main.cpp.o: in function `main':
/home/m/CLionProjects/ORB_SLAM/src/main.cpp:20: undefined reference to `cv::VideoCapture::VideoCapture(std::string const&, int)'

For the code

#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
//#include <open3d/Open3D.h>

int main() {
    cv::VideoCapture cap("/home/.../scene.mp4");
    //auto sphere = open3d::geometry::TriangleMesh::CreateSphere(1.0);  

It seems as though Open3D::Open3D takes precedence over opencv_calib3d;opencv_core;.... What is causing this and how can I fix it? Is this perhaps due to the discrepancy in Open3D’s “::” vs OpenCV’s lowercase notation?

Here is a dump of all CMake variables if it is of any use

Excuse my inexperience. I have searched through CMake documentation and Stackoverflow questions for a lead, but so far I have found nothing.

Any input, also non-solution, will do.
Have I misunderstood something fundamental about CMake?
Is this just an odd unfortunate glitch of something that should normally work?

Hmm. Open3D::Open3D is probably fine. Can you show what it has in its target properties (somewhere under that Open3D_DIR path. Can you show the command lines generated for the compile and link commands (make VERBOSE=1 or ninja -v) in the various situations?

Is it possible that Open3D is finding its own OpenCV as well?

Thank you for your quick reply!

Open3D_DIR contains 4 files,
Open3DConfig.cmake Open3DTargets.cmake
Open3DConfigVersion.cmake Open3DTargets-relwithdebinfo.cmake

Which I have uploaded here. Cmake_Open3d - Google Drive

I also ran the commands and posted the outputs here:
make VERBOSE=1:
ninja --verbose:

Your comment led me to this issue on github, which may be the culprit. Errors occur when Open3D library is linked together with other libraries, e.g. gflags, opencv · Issue #2286 · isl-org/Open3D · GitHub

I will attempt the fixes proposed in that thread and report back. Thanks for the help!