I have a problem with following C++ code built with CMake:
#include <iostream> #include <dlfcn.h> int main() { void* vulkanLibrary = dlopen( "libvulkan.so.1", RTLD_NOW ); if(vulkanLibrary) return 0; else return 1; } And here the CMakeLists:
cmake_minimum_required(VERSION 3.14) project(VulkanTest) set(CMAKE_CXX_STANDARD 17) add_link_options(-ldl) add_executable(VulkanTest main.cpp) Build Output:
/opt/JetBrains/CLion-2019.2/bin/cmake/linux/bin/cmake --build /home/eriksimon/CLionProjects/VulkanTest/cmake-build-debug --target VulkanTest -- -j 4 -- Configuring done -- Generating done -- Build files have been written to: /home/eriksimon/CLionProjects/VulkanTest/cmake-build-debug [ 50%] Linking CXX executable VulkanTest /usr/bin/ld: CMakeFiles/VulkanTest.dir/main.cpp.o: in function `main': /home/eriksimon/CLionProjects/VulkanTest/main.cpp:5: undefined reference to `dlopen' collect2: error: ld returned 1 exit status make[3]: *** [CMakeFiles/VulkanTest.dir/build.make:84: VulkanTest] Error 1 make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/VulkanTest.dir/all] Error 2 make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/VulkanTest.dir/rule] Error 2 make: *** [Makefile:118: VulkanTest] Error 2 I get the linker error on dlopen reported as undefined reference. When googling this, I only found Posts telling to link with "-ldl" linker flag. Looks like I am setting it in my CMake file, though. What is the reason for it not being used by the linker?
make, runmake VERBOSE=1and provide the output for that. This will give us a lot more information about what is going on...make VERBOSE=1in the build directory and provide the output.make: *** No targets specified and no makefile found. Stop.