Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to compile in C project #46

Closed
photodiode opened this issue Oct 18, 2018 · 3 comments
Closed

Trying to compile in C project #46

photodiode opened this issue Oct 18, 2018 · 3 comments

Comments

@photodiode
Copy link

Hi,
I tried including VMA in my C project using:

#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"

but when I compile with gcc (-std=c11) I get this error:

In file included from src/vulkan.c:11:0:
src/vk_mem_alloc.h:2616:10: fatal error: cstdint: No such file or directory
 #include <cstdint>
          ^~~~~~~~~
compilation terminated.

I wouldn't be surprised if I'm just missing something obvious, but I can't figure out what.

Any help would be much appreciated.
Thank you.

@calper-ql
Copy link

Have you considered including

#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"

in a C++ file and than linking against that ?

In the documentation it says:

To do it properly:

  1. Include "vk_mem_alloc.h" file in each CPP file where you want to use the library. This includes declarations of all members of the library.
  2. In exacly one CPP file define following macro before this include. It enables also internal definitions.
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"

It may be a good idea to create dedicated CPP file just for this purpose.

@photodiode
Copy link
Author

photodiode commented Oct 18, 2018

I must have misunderstood that part.

Making a standalone vma.cpp and including only those two lines, then compiling using
g++ -g -c vma.cpp -lvulkan -o vma.o

And then including vma.o in my C project compilation together with -lstdc++ like this
gcc vulkan.c vma.o -std=c11 -Wall -lvulkan -lstdc++ -o vulkan
seems to work.

Not including -lstdc++ gives me this error message when I run the program
./vulkan: symbol lookup error: vulkan: undefined symbol: __cxa_pure_virtual

This works fine I guess.
Thank you for the suggestion!

@adam-sawicki-a
Copy link
Contributor

That's right. This library is written in C++, but has C-compatible interface. Thus you can include and use vk_mem_alloc.h in C or C++ code, but full implementation with VMA_IMPLEMENTATION macro must be compiled as C++, NOT as C. I've clarified this in the documentation. Thanks for this question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants