RobLoach / raylib-nuklear

Nuklear immediate mode GUI for raylib
https://robloach.github.io/raylib-nuklear/
zlib License
151 stars 22 forks source link

Errors when including raylib-nuklear.h #36

Closed samfromcadott closed 2 years ago

samfromcadott commented 2 years ago

I'm attempting to compile the example in the read me. I'm using Clang in Ubuntu (in WSL) and cross compiling to Windows. I get these errors when compiling:

clang++ -o main.o -c -static --target=x86_64-w64-windows-gnu -std=c++17 -Iinclude main.cpp
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:45:
include/nuklear.h:435:1: error: '_dummy_array435' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
include/nuklear.h:436:1: error: '_dummy_array436' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:5813:1: error: '_dummy_array5813' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:5814:1: error: '_dummy_array5814' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_ptr) == sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:6442:13: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        t = (nk_ptr)src; /* only need low bits */
            ^~~~~~~~~~~
include/nuklear.h:6443:18: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        if ((t | (nk_ptr)dst) & nk_wmask) {
                 ^~~~~~~~~~~
include/nuklear.h:6444:22: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
            if ((t ^ (nk_ptr)dst) & nk_wmask || length < nk_wsize)
                     ^~~~~~~~~~~
include/nuklear.h:6459:13: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        t = (nk_ptr)src;
            ^~~~~~~~~~~
include/nuklear.h:6460:18: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        if ((t | (nk_ptr)dst) & nk_wmask) {
                 ^~~~~~~~~~~
include/nuklear.h:6461:22: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
            if ((t ^ (nk_ptr)dst) & nk_wmask || length <= nk_wsize)
                     ^~~~~~~~~~~
In file included from main.cpp:2:
include/raylib-nuklear.h:456:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:470:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:484:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:752:11: error: cannot initialize a variable of type 'Texture *' with an rvalue of type 'void *'
        Texture* stored_tex = malloc(sizeof(Texture));
                 ^            ~~~~~~~~~~~~~~~~~~~~~~~
14 errors generated.
samfromcadott commented 2 years ago

It seems like removing -static --target=x86_64-w64-windows-gnu gets rid of these errors, but also prevents cross compilation.

aiq commented 2 years ago

Hi, I get the same error in the following environment:

Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
aiq commented 2 years ago

The m1 seems to make some problems it was necessary to add __aarch64__:

From: #if defined(__x86_64__) || defined(__ppc64__)

To: #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__)

RobLoach commented 2 years ago

Would you be able to push up a Pull Request? Idd be happy to fix the upstream for this too.

aiq commented 2 years ago

Hi, also does the use of #define NK_INCLUDE_FIXED_TYPES solve this problem.

RobLoach commented 2 years ago

With INCLUDE_FIXED_TYPES, I'm getting some conflicts when compiling the demos.

RobLoach commented 2 years ago

I've tweaked some of the defines. Mind having another look?

aiq commented 2 years ago

@RobLoach do you mean @samfromcadott ? Because I don't see relevant changes after my commit.

RobLoach commented 2 years ago

Moved some of the defines to above the header: https://github.com/RobLoach/raylib-nuklear/blob/master/include/raylib-nuklear.h#L43-L53

aiq commented 2 years ago

it works fine on my system

RobLoach commented 2 years ago

Thanks for checking!