#Setting up with CMAKE

71 messages · Page 1 of 1 (latest)

thick blaze
#

Was trying to set up vulkan with CMAKE for the first time.

cmake_minimum_required(VERSION 3.10)

project(VulkanApp)
find_package(Vulkan REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(VulkanApp main.cpp)

target_include_directories(VulkanApp PUBLIC ${VULKAN_INCLUDE_DIR})
target_link_libraries(VulkanApp ${Vulkan_LIBRARY})

message("Vulkan_INCLUDE_DIR: ${VULKAN_INCLUDE_DIR}")
message("VULKAN_LIBRARY: ${VULKAN_LIBRARY}")

Both the Library and Include dirs are printed as ```cmd
Vulkan_INCLUDE_DIR: C:/VulkanSDK/1.3.290.0/Include
Vulkan_LIBRARY: C:/VulkanSDK/1.3.290.0/Lib/vulkan-1.lib
-- Configuring done (5.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/mitta/dev/VulkanApp

But when I run make, it throws 
```cmd
CMakeFiles\VulkanApp.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xa1): undefined reference to `vkCreateInstance@12'
CMakeFiles\VulkanApp.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x111): undefined reference to `vkDestroyInstance@8'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [VulkanApp.exe] Error 1
make[1]: *** [CMakeFiles/VulkanApp.dir/all] Error 2
make: *** [all] Error 2```
atomic scarab
#

Vulkan_LIBRARY should it perhaps be uppercase? as is in the message statement

thick blaze
atomic scarab
thick blaze
thorn vigil
#

@thick blaze

cmake_minimum_required(VERSION 3.10)

project(VulkanApp)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include_directories(
  C:/User/../VulkanSDK/Include # Add the path manually
   # ... Add more include paths
)

link_directories(
   C:/Users/../VulkanSDK/Lib
   # ... Add more library paths
)

add_executable(VulkanApp main.cpp)

target_link_libraries(VulkanApp vulkan-1)
#

Also, I suggest using

file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/YourSrcPath/*.cpp")

add_executable(YourProjectName ${SOURCE_FILES})```
When working with Multiple files.
#

And:

file(GLOB_RECURSE HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/YourSrcPath/*.hpp")

include_directories(
  C:/User/../VulkanSDK/Include # Add the path manually
   ${HEADER_FILES}
   # ... Add more include paths
)
thick blaze
#

@thorn vigil I think there is something seriously wrong with my installation or smthing

thorn vigil
thick blaze
#

same output

thorn vigil
#

Can you show me your main.cpp file?

thick blaze
atomic scarab
thorn vigil
#

@thick blaze Can you try using the CMAKE Extension?

#

I usually don't do terminal command.

thick blaze
thorn vigil
thick blaze
atomic scarab
thorn vigil
thick blaze
#

nop

atomic scarab
# thick blaze

can you check the generated make files what is the link command for the vulkanapp.exe?

and try it directly from the command line?

thorn vigil
#

It's my comment.

#

I gave the full guided on setting up Vulkan on VSCode.

thick blaze
thorn vigil
#

@thick blaze Wait.

#

Can you go to CMD Prompt?

#

And type in: vkinfo

#

If it works, your Vulkan bin is on your path, else not.

thick blaze
#

interesting

#

not recog

thorn vigil
thick blaze
#

yes..?

thorn vigil
#

@thick blaze Try, vulkaninfo

#

On the CMD Prompt.

thick blaze
#

huge dump

thorn vigil
#

That's a good sign.

thick blaze
#

hmm

thorn vigil
thick blaze
#

ryt

#

VkPhysicalDeviceVulkan13Features:

    robustImageAccess                                  = true
    inlineUniformBlock                                 = true
    descriptorBindingInlineUniformBlockUpdateAfterBind = true
    pipelineCreationCacheControl                       = true
    privateData                                        = true
    shaderDemoteToHelperInvocation                     = true
    shaderTerminateInvocation                          = true
    subgroupSizeControl                                = true
    computeFullSubgroups                               = true
    synchronization2                                   = true
    textureCompressionASTC_HDR                         = false
    shaderZeroInitializeWorkgroupMemory                = true
    dynamicRendering                                   = true
    shaderIntegerDotProduct                            = true
    maintenance4                                       = true
#

alot of this

thorn vigil
#

Yeahh, that's nice.

#

So, I want you to download Ninja.

thick blaze
#

id do that
but shouldnt it work without that

thorn vigil
#

We don't seem to have much of a choice.

thick blaze
#

ill try it out tho
ill get back to ya later today
if that doesnt work

thorn vigil
#

My comment.

atomic scarab
# thick blaze

i think this doesn't link to anything, atleast i don't see any vulkan lib being mentioned in here

thick blaze
thick blaze
# thorn vigil We don't seem to have much of a choice.

I tried ninja
same thing

CMakeFiles/VulkanApp.dir/main.cpp.obj:main.cpp:(.text+0xa1): undefined reference to `vkCreateInstance@12'
CMakeFiles/VulkanApp.dir/main.cpp.obj:main.cpp:(.text+0x111): undefined reference to `vkDestroyInstance@8'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
atomic scarab
thick blaze
#

I was able to get out of this error
Apparently I was running the c header
and needed the c++ wrapped header

#

by making it vulkan.hpp

#

but onto the next error

#
C:/VulkanSDK/1.3.290.0/Include/vulkan/vulkan.hpp:19:25: fatal error: string_view: No such file or directory
 #  include <string_view>
                         ^```
#

@atomic scarab

atomic scarab
# thick blaze ```cmd C:/VulkanSDK/1.3.290.0/Include/vulkan/vulkan.hpp:19:25: fatal error: stri...

i guess the default language standard on mings is pre-17, so it doesn't see string_view header

you need to add something like this to the cmake:

target_compile_features(${target_name} PUBLIC cxx_std_23)
    set_target_properties(${target_name} PROPERTIES CXX_STANDARD_REQUIRED ON)
    set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF)

just replace ${target_name} with VulkanApp in your case, and set the standard 17/20/23 to what your toolchain supports

alternatively, you can set VULKAN_HPP_CPP_VERSION to 11 or 14, if you really want to use c++11 or c++14 only https://github.com/KhronosGroup/Vulkan-Hpp/blob/main/vulkan/vulkan.hpp#L19

but tbh it should have worked with the C header, those functions are from the C API, if it was the headers fault the compiler would complain, not the linker

GitHub

Open-Source Vulkan C++ API. Contribute to KhronosGroup/Vulkan-Hpp development by creating an account on GitHub.

thick blaze
#

I just switched to my wsl
it works perfectly there
ig this was just silly me

#

thanks for the help tho

atomic scarab
#

that also might not be the best idea 😁 I'm not sure if there is any way to make it see the gpu in the wsl

on windows i usually stick to using msvc community edition