I want to learn programming with Vulkan. My first step was to enumerate the Vulkan extensions count available on my system. So I wrote this simple code:
#include <iostream>
#include <vulkan/vulkan.hpp>
int main(int argc, char *argv[])
{
VkResult ret;
unsigned int propertyCount;
ret = vkEnumerateInstanceExtensionProperties(NULL, &propertyCount, NULL);
if (ret != VK_SUCCESS)
return 1;
std::cout << "Vulkan: Extension Count: " << propertyCount << std::endl;
return 0;
}
When I try to compile and link the code I get an undefined reference error:
$ g++ -lvulkan -o vkExtension vkExtension.cpp
/usr/bin/ld: /tmp/user/1000/ccgB9M9N.o: in function `main':
vkExtension.cpp:(.text+0xc99): undefined reference to `vkEnumerateInstanceExtensionProperties'
collect2: error: ld returned 1 exit status
$
Although libvulkan is installed on my system (Debian 12):
$ cd /usr/lib/x86_64-linux-gnu
$ ls -la | grep libvulkan
-rw-r--r-- 1 root root 8575696 Mar 22 2023 libvulkan_intel_hasvk.so
-rw-r--r-- 1 root root 11115728 Mar 22 2023 libvulkan_intel.so
-rw-r--r-- 1 root root 6918024 Mar 22 2023 libvulkan_lvp.so
-rw-r--r-- 1 root root 8711344 Mar 22 2023 libvulkan_radeon.so
lrwxrwxrwx 1 root root 14 Feb 6 2023 libvulkan.so -> libvulkan.so.1
lrwxrwxrwx 1 root root 20 Feb 6 2023 libvulkan.so.1 -> libvulkan.so.1.3.239
-rw-r--r-- 1 root root 457224 Feb 6 2023 libvulkan.so.1.3.239
$
I have examined the library by itself for the missing functions (symbols) too, but should be available in the installed library. The command nm doesn't list any symbols, because the library is stripped. So I used readelf:
$ readelf -s --wide libvulkan.so.1.3.239 | grep vkEnumerateInstance
136: 0000000000034850 687 FUNC GLOBAL DEFAULT 12 vkEnumerateInstanceExtensionProperties
170: 0000000000034b00 639 FUNC GLOBAL DEFAULT 12 vkEnumerateInstanceLayerProperties
283: 0000000000034d80 709 FUNC GLOBAL DEFAULT 12 vkEnumerateInstanceVersion
$
I have also checked the default library search path from the linker (GNU ld), but the path is correct.
Something missing?
(There is a similar question on SO too. But unfortunately with no answer.)
UPDATE
Seems the issue is GNU GCC/ld related. Have tried to build the code with clang++/LLVM, with success:
$ clang++ -Wall -Wextra -lvulkan -o vkExtension vkExtension.cpp
vkExtension.cpp:5:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[])
^
vkExtension.cpp:5:26: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char *argv[])
^
2 warnings generated.
$ ./vkExtension
Vulkan: Extension Count: 20
$
Have updated the question title too.