Closed rokups closed 2 years ago
You're actually in the opposite situation, by using g++
you're building main.c
as C++. (g++
doesn't try to auto-detect the language like gcc
does.) You can either build them separately or specify the language explicitly:
g++ -I../imgui -x c main.c -x c++ cimgui.cpp ../imgui/imgui.cpp ../imgui/imgui_demo.cpp ../imgui/imgui_draw.cpp ../imgui/imgui_tables.cpp ../imgui/imgui_widgets.cpp
(There's an additional unrelated issue with extern "C"
being combined with static. Remove the #define CIMGUI_API extern "C"
in cimgui.cpp to fix that temporarily. More info here: https://github.com/dearimgui/dear_bindings/issues/14)
Even though C++ users shouldn't really be using cimgui.h
, it should include an extern "C"
block when it's built as C++ to protect against this scenario. IE:
#ifndef IMGUI_H
#ifdef __cplusplus
extern "C"
{
#endif
// dear imgui, v1.84 WIP
// ...header contents goes here...
#ifdef __cplusplus
}
#endif
#endif
After this change, the explicit extern "C"
block in the generated cimgui.cpp
can be removed.
This i was not aware of, thank you! Explicitly specifying language worked, sample application builds without issues. I will add it to CI then. 🤝
No problem! It's definitely not the most intuitive, my initial instinct is always g++
should be the auto-detecting one too.
I think that with the recent changes to add extern "C"
to the header this should work now either way, but let me know if something is still broken!
Can confirm compilation with g++ without explicitly specifying source code type now works. Thanks! 🙏🏻
My understanding is that GCC uses C++ name mangling because
cimgui.h
is included within a namespace. Movingcimgui.h
out of namespace creates name collisions between generated and original enums.