raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.61k stars 303 forks source link

Multiple definitions of raygui functions #409

Closed Vi-dot1 closed 3 months ago

Vi-dot1 commented 5 months ago

I've been having problems implementing raygui 4 in my current raylib project in C++, each time I try to build it the terminal shows several lines like this for several functions inside raygui.h:

[build] C:/path../to../project../src/raygui.h:2839: multiple definition of `GuiValueBox'; CMakeFiles\RayDraw.dir/objects.a(gui.cpp.obj):C:/path../to../project../src/raygui.h:2839: first defined here

And so on for multiple Gui functions.

I implemented raygui on its own header file kind of like this:

#pragma once
/* gui.h */

extern "C"{
    #include"raylib.h"

    #define RAYGUI_IMPLEMENTATION
    #include"raygui.h"
}

void drawGui();

And a source file where I include the header and define the draw function. I tried changing RAYGUI_IMPLEMENTATION to RAYGUI_STATIC but that just makes makes the functions invisible to the compiler


I'm not sure if this is related, but I'm also getting a bunch of warnings about enum mismatches:

enumerated mismatch in conditional expression: 'GuiControlProperty' vs 'GuiDefaultProperty' [-Wenum-compare]

They seem to come from different places in raygui.h from these calls, which return values from two different enums depending on the result:

GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR))

That should probably go on its own issue, but I saying it here just in case is somehow related to my problem

Futuremappermydud commented 5 months ago

This is so Confusing!!! The Readme says you only need to define RAYGUI_IMPLEMENTATION once yet half the functions are only defined under RAYGUI_IMPLEMENTATION... Aghhhh!!!!

Vi-dot1 commented 4 months ago

Ok I'm not even sure why it only works this way, but by including raygui.h into the source file instead of the header fixes my issue:

/*gui.cpp*/
extern "C"{
    #include"raylib.h"

    #define RAYGUI_IMPLEMENTATION 1
    #include"raygui.h"
}

#include"gui.h"

void drawGui()
{...}

The first time I try to build it with CMake I still get the enum mismatch warnings, but after that it compiles with no problem