greenfork / nimraylib_now

The Ultimate Raylib gaming library wrapper for Nim
MIT License
151 stars 17 forks source link

wrong import order in the c files (tested on windows) #50

Closed enthus1ast closed 2 years ago

enthus1ast commented 2 years ago

Another flavour of:

49

12

main.nim

import os
import nimraylib_now/mangled/raylib  # Vector2
import nimraylib_now/mangled/raymath # Vector2
import moduler
initWindow(20, 20, "thread bug")

var threadPhysic: Thread[int]

createThread(threadPhysic, threadSystemPhysic, 10)
while true:
  var vv = Vector2(x: 0.1, y: 0.2) + 0.1  # <- this uses raymath.h ; and let nim include it in the c file
  sleep(500)
closeWindow()

moduler.nim

import nimraylib_now/mangled/raylib  # Vector2
import nimraylib_now/mangled/raymath # Vector2
import os

proc threadSystemPhysic*(foo: int) {.thread.} =
  discard
  while true:
    echo "tick"
    sleep (100)

compile with:

nim c --threads:on main.nim

PS C:\Users\david> nim c  --threads:on -r "c:\Users\david\projects\nimPlayground\main.nim"
Hint: used config file 'C:\Users\david\.choosenim\toolchains\nim-1.6.0\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\david\.choosenim\toolchains\nim-1.6.0\config\config.nims' [Conf]
....................................................................................................
c:\Users\david\projects\nimPlayground\moduler.nim(1, 29) Warning: imported and not used: 'raylib' [UnusedImport]
c:\Users\david\projects\nimPlayground\moduler.nim(2, 29) Warning: imported and not used: 'raymath' [UnusedImport]
c:\Users\david\projects\nimPlayground\main.nim(11, 7) Hint: 'vv' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_digitsutils.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: stdlib_dynlib.nim
CC: stdlib_winlean.nim
CC: stdlib_times.nim
CC: stdlib_os.nim
CC: moduler.nim
CC: main.nim
In file included from C:\Users\david\nimcache\main_d\@mmain.nim.c:12:
C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raymath.h: In function 'MatrixFrustum':
C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raymath.h:1240:82: error: parameter name omitted
 1240 | RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far)
      |                                                                                  ^~~~~~
C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raymath.h:1240:95: error: parameter name omitted
 1240 | RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far)
      |                                                                                               ^~~~~~
C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raymath.h:1246:34: error: expected expression before ')' token       
 1246 |     float fn = (float)(far - near);
      |                                  ^
compilation terminated due to -fmax-errors=3.
Error: execution of an external compiler program 'gcc.exe -c  -w -fmax-errors=3 -mno-ms-bitfields -DWIN32_LEAN_AND_MEAN -Wall -D_DEFAULT_SOURCE -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -s -O1 -Werror=implicit-function-declaration -IC:\Users\david\projects\nimraylib_now\src\csources\raylib_mangled -IC:\Users\david\projects\nimraylib_now\src\csources\raylib_mangled\external\glfw\include -IC:\Users\david\projects\nimraylib_now\src\csources\raylib_mangled\external\glfw\deps\mingw -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33   -IC:\Users\david\.choosenim\toolchains\nim-1.6.0\lib -Ic:\Users\david\projects\nimPlayground -o C:\Users\david\nimcache\main_d\@mmain.nim.c.o C:\Users\david\nimcache\main_d\@mmain.nim.c' failed with exit code: 1

as soon a proc from raymath.h is used in the main.nim the c includes are in the wrong order (windows.h is moved above the raymath.h include):

#include "nimbase.h"
#include "C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raylib.h"
#include <windows.h>
#include <setjmp.h>
#include <string.h>
#include "C:\Users\david\projects\nimraylib_now\src\nimraylib_now\mangled\raymath.h"
greenfork commented 2 years ago

The problem is not present on arch linux. Further investigation is needed.

EDIT: lol the problem is with windows.h, it's not linux for sure

enthus1ast commented 2 years ago

If you need me for testing let me know

greenfork commented 2 years ago

@enthus1ast I invited you as a collaborator to the project. So here you would want to read a bit about HACKING. I made a PR https://github.com/greenfork/nimraylib_now/pull/51 that does name mangling for more names, you would want to get this branch and add more names as needed, then run nimble convert to regenerate all the files and try to compile your example again. Eventually all conflicting symbols will be resolved.

You would also want to run nimble develop in the project root to avoid reinstalling this package everytime.

Let me know if you need any help with that.