Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.12k stars 513 forks source link

cmake issues #140

Closed kershnerd closed 5 years ago

kershnerd commented 5 years ago

Here is my CMakeLists.txt:

project(triangle2)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES main.cpp)
add_executable(triangle2 ${SOURCE_FILES})

find_package(PkgConfig REQUIRED)

pkg_search_module(GLFW REQUIRED glfw3)

include_directories(${GLFW_INCLUDE_DIRS})

find_package(Vulkan REQUIRED)

find_package(glm REQUIRED)

target_link_libraries(triangle2 ${GLFW_LIBRARIES} ${Vulkan_LIBRARIES})

I am getting the follow error when linking:

/usr/bin/ld: //usr/local/lib/libglfw3.a(posix_thread.c.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line

I think this is relating to needing the link with -ldl but not sure how to do that in a CMakeLists.txt. I tried this but it didn't work:

target_link_libraries(triangle2 ${GLFW_LIBRARIES} ${Vulkan_LIBRARIES} ${CMAKE_DL_LIBS})

Any ideas?

Overv commented 5 years ago

Could you add your solution to this issue?

kershnerd commented 5 years ago

Yes.. the problem was that I was linking to the dynamic libraries of GLFW. I needed to link to the static libraries.

So for example, in the CMakeLIsts.txt file, I need to do this:

# GLFW
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})

# Vulkan
find_package(Vulkan REQUIRED)

# Add your executables here
add_executable(example1 main.cpp)

# linker
target_link_libraries(example1 ${GLFW_STATIC_LIBRARIES} ${Vulkan_LIBRARIES})