No C++ support when including C++ header-only file in C project
Answered
I'm using the following header-only C++ file in my project: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/blob/master/src/vk_mem_alloc.h
The code in my project (apart from this file) is in C, and CLion seems to have trouble with the C++ parts of this header file (can't find cstdlib and all other C++ includes, can't resolve class, templates, etc).
My toolchains work correctly and I can use the header file the same way without problem in a C++ project.
Does CLion support calling C++ code from C?
Please sign in to leave a comment.
Hi, Jeremie! Please show your CMakeLists.txt.
Here it is:
Jeremie, it's not possible to use C and C++ languages in one file as is, but there are some ways to mix them. Please take a look at, for example, this article. In my opinion, the most simple option is to create a C++ project (in other words, to rename your main.c into main.cpp and reload the CMake project) and wrap your C code into extern "C" {}.
Thanks, separating the header into .h/.cpp did the trick.