C++ FreeBSD-14 Vulkan-headers compile error

I'm trying to compile this simple vulkan instance(Basically the vulkan tutorial) with GLFW(3.3.8) and Vulkan-headers(1.3.273) all from the pkg repo. I'm using the build2 build system with clang++. Although it doesn't matter whether I use G++ with libstdc++ or the system default. It keeps complaining about a similar error.

What I have installed through pkg:
- vulkan-extension-layer-1.3.272
- vulkan-headers-1.3.273
- vulkan-validation-layers-1.3.273
- vulkan-tools-1.3.273
- glfw-3.3.8

It works on Windows 10 and WSL2(Ubuntu), but not on FreeBSD for some reason. Don't know if it's a version mismatch or something along those lines. Have not tried it on a complete linux userland through linuxulator.

Output:
Code:
c++ cxx{vulk} -> ../../vulk-freebsd-clang-debug/vulk/vulk/obje{vulk}
In file included from /home/bsd/repos/build2/c++/exe/build2-vulk/vulk/vulk/vulk.cxx:3:
In file included from /usr/local/include/vulkan/vulkan.hpp:8562:
/usr/local/include/vulkan/vulkan_structs.hpp:16076:9: error: member initializer '__major' does not name a non-static data member or base class
      : major( major_ )
        ^~~~~~~~~~~~~~~
/usr/include/sys/types.h:329:18: note: expanded from macro 'major'
#define major(d)        __major(d)
                        ^~~~~~~~~~
In file included from /home/bsd/repos/build2/c++/exe/build2-vulk/vulk/vulk/vulk.cxx:3:
In file included from /usr/local/include/vulkan/vulkan.hpp:8562:
/usr/local/include/vulkan/vulkan_structs.hpp:16077:9: error: member initializer '__minor' does not name a non-static data member or base class
      , minor( minor_ )
        ^~~~~~~~~~~~~~~
/usr/include/sys/types.h:335:18: note: expanded from macro 'minor'
#define minor(d)        __minor(d)
                        ^~~~~~~~~~
2 errors generated.
error: process clang++ exited with code 1
  info: command line: clang++ -I/usr/local/include/vulkan -I/home/bsd/repos/build2/c++/exe/build2-vulk/vulk-freebsd-clang-debug/vulk -I/home/bsd/repos/build2/c++/exe/build2-vulk/vulk -std=c++2b -g -Wno-unqualified-std-cast-call -isystem /usr/local/include -fdiagnostics-color -finput-charset=UTF-8 -o ../../vulk-freebsd-clang-debug/vulk/vulk/vulk.o -c -x c++ /home/bsd/repos/build2/c++/exe/build2-vulk/vulk/vulk/vulk.cxx
  info: while updating ../../vulk-freebsd-clang-debug/vulk/vulk/obje{vulk}
  info: while updating ../../vulk-freebsd-clang-debug/vulk/vulk/exe{vulk}
  info: while updating ../../vulk-freebsd-clang-debug/vulk/dir{vulk/}
info: failed to update ../../vulk-freebsd-clang-debug/vulk/dir{vulk/}

Anyone else experience similar issues?
 
Last edited by a moderator:
Update:

Tried the same thing in a VM on a different machine with an Xorg KDE DE and it still gives the same result. Also tried compiling vulkan-tools from /usr/ports. Which to my surprise, compile fine. After uninstalling vulkan-tools. I installed all of the dependencies vulkan-tools requires listed on freshports through pkg to see if my code would somehow compile to only yield the same error.

If anyone is interested in running the code it's here. https://pastebin.com/pJr8kEda
Although it should not really matter since the error hits early on the headers themselves.

I don't think it's the build system itself. As doing "g++ vulk.cxx -o vulk" has the same result for gcc and therefore should be irrelavent.

If anyone wants to try it through build2 anyway.

Do:

pkg install build2 # Ideally you would want to download it from the official install instructions: https://build2.org/install.xhtml
pkg install vulkan-extension-layer
pkg install vulkan-headers
pkg install vulkan-validation-layers
pkg install glfw
pkg install libglu

mkdir -p ~/tmp/vulk.d
cd ~/tmp/vulk.d
bdep new -l c++ -t exe vulk
cd vulk

*Copy paste the code from the pastebin link* into vulk/vulk.cxx

At this point just run the command "b" in your current directory which would be ~/tmp/vulk.d/vulk and you should see a similar error.

To save a config with compile options do: bdep init -C @clang-debug cc config.cxx="clang++ -g"
or to just change compile options `b config.cxx="clang++ -g"`
then run "b" or "bdep update @clang-release". You can change the settings inside config.cxx to whatever you want. E.G `b config.cxx="g++ -g"` gives slightly different but same errors.

The compiler already understands where the pkg installed libraries are so communicating this info with the build system is unnecessary. Even when doing so the result doesn't change.

Would be useful to know if this is a software or hardware issue.
 
/usr/include/sys/types.h:335:18: note: expanded from macro 'minor'
#define minor(d) __minor(d)
^~~~~~~~~~

Thats fairly disgusting.

A system macro that doesn't use all caps in order to make it obvious that it is VERY UGLY and should only be used as a last resort.

In order to fix that you need to work out your header dependencies. Then you can write something like

C++:
#include "header_that_includes_sys_types.h"
#if defined(minor)
#undef minor
#endif
#include <vulkan.hpp>

(sys/types.h might also be included directly).
 
In order to fix that you need to work out your header dependencies. Then you can write something like

C++:
#include "header_that_includes_sys_types.h"
#if defined(minor)
#undef minor
#endif
#include <vulkan.hpp>

(sys/types.h might also be included directly).

After adding the following to the top and telling the system linker which libs to use it compiles and runs fine.
C++:
#if defined __FreeBSD__
#include <sys/types.h>
#if defined(minor)     
#undef minor           
#endif                 
#endif // FreeBSD
 
Back
Top