Giter Club home page Giter Club logo

Comments (9)

smalls12 avatar smalls12 commented on July 17, 2024

Should also note that this also creates a slew of compiler warnings.

from raygui.

raysan5 avatar raysan5 commented on July 17, 2024

It should probably be redesigned...

from raygui.

smalls12 avatar smalls12 commented on July 17, 2024

I don't think it would be too hard to keep the definitions in the header, and build a library for the actual implementation.
This would break the header only design, but in the long run might be more maintainable.
This would also follow what raylib does.

from raygui.

raysan5 avatar raysan5 commented on July 17, 2024

@smalls12 I redesigned the functions definition settings in commit 09d5836.

Now it should work as expected:

#include "raylib.h"

#define RAYGUI_IMPLEMENTATION
//#define RAYGUI_STATIC    // Only if you want to keep raygui functionality internal to current module
#include "raygui.h"

from raygui.

smalls12 avatar smalls12 commented on July 17, 2024

Okay appears to be working now.
I do get the following warning though.

In file included from /src/scratch/blokus/src/StartScreen.cpp:3:0:
/src/staging/usr/include/raygui.h:144:0: warning: "RAYGUIDEF" redefined
         #define RAYGUIDEF extern "C"    // Functions visible from other files (no name mangling of functions in C++)
 
/src/staging/usr/include/raygui.h:137:0: note: this is the location of the previous definition
 #define RAYGUIDEF               // We are building or using raygui as a static library (or Linux shared library)

from raygui.

raysan5 avatar raysan5 commented on July 17, 2024

Yeah, I simplified the conditions to work better but it involved redefining the define when required.

from raygui.

daidalo-s avatar daidalo-s commented on July 17, 2024

Hi, i'm commenting on this closed issue since i'm having a similar problem with the original comment.
Like in the first comment, i'm developing a C++ application where i wrap all the different raygui elements into it's own class (I'm a beginner so sorry if this is a very stupid questions).
I'm downloading the latest raylib version using CMake

FetchContent_Declare(
        raylib
        GIT_REPOSITORY "https://github.com/raysan5/raylib.git"
        GIT_TAG "master"
        GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(raylib)

and i have copied both the raylib and the raygui header files into a folder in my project i called include.
Than in my main file (main.cpp) i have

#include "./include/raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "./include/raygui.h"
#include "./include/button.hpp"

and in my button.h

#include "./raylib.h"
#include "./raygui.h"

The error i'm getting is

In file included from /Users/lorenzo/Developer/battaglia_navale/src/main.cpp:7:
In file included from /Users/lorenzo/Developer/battaglia_navale/src/./include/button.hpp:6:
/Users/lorenzo/Developer/battaglia_navale/src/./include/raygui.h:1072:21: error: redefinition of 'guiIcons'
static unsigned int guiIcons[RAYGUI_ICON_MAX_ICONS*RAYGUI_ICON_DATA_ELEMENTS] = {

Looking at the raygui.hfile i can see the problem, there are parts of code that are not guarded from multiple inclusions. Am i misinterpreting the warning

NOTE: raygui is a single-file header-only library (despite its internal dependency on raylib), so, functions definition AND implementation reside in the same file raygui.h, when including raygui.h in a module, RAYGUI_IMPLEMENTATION must be previously defined to include the implementation part of raygui.h BUT only in one compilation unit, other modules could also include raygui.h but RAYGUI_IMPLEMENTATION must not be defined again.

in the raygui README?

from raygui.

raysan5 avatar raysan5 commented on July 17, 2024

@daidalo-s The solution I use for those cases is:

#include "./include/raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "./include/raygui.h"
#undef RAYGUI_IMPLEMENTATION                // Avoid including raygui implementation again

from raygui.

daidalo-s avatar daidalo-s commented on July 17, 2024

Thanks a lot! This worked!

from raygui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.