Hello, I'm trying to wrap the GameMusicEmu lib, a lib that allows you to play various musics from old chiptune systems such as NES or MegaDrive but when I compile my project, it compiles without any errors but when I run the output exe, it instantly crash with this error :
could not import: gme_ay_type
which is declared there :
we checked the dll and seems theses symbols (gme_xxx_type, where xxx is the system) doesn't exists in the dll. libgme is a C++ lib, so, how can I wrap this without problems? Is it possible? Thanks for the answer.
here this is my repo that contains the GME wrapping (it will be moved to another repo when finished) : https://github.com/system64MC/NimTilengine
here the repo of the GME library : https://github.com/ShiftMediaProject/game-music-emu
I'm on Windows and someone tried it on Linux on libgme 0.6.x, seems working fine but without music (it's an SPC file)
Looking closer, I have never mapped global variables between Nim and C/C++; I have only mapped types and procs.
Does it work if you remove the {.importc: .. dynlib: libgmedll.} parts from those declarations?
Did you try this?
var
gmeAyType*: GmeTypeT
gmeGbsType*: GmeTypeT
gmeGymType*: GmeTypeT
gmeHesType*: GmeTypeT
gmeKssType*: GmeTypeT
gmeNsfType*: GmeTypeT
gmeNsfeType*: GmeTypeT
gmeSapType*: GmeTypeT
gmeSpcType*: GmeTypeT
gmeVgmType*: GmeTypeT
gmeVgzType*: GmeTypeT
[ Again, this is someone coming from someone not familiar with mapping global variables between Nim and C++ dll. ]
Wait, it's not a crash.. it's a similar mapping to a global var that's failing..
Here too, try changing to var gmeWrongFileType*: cstring.
Now it says that :
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Try translating the repo's demo/basic.c example to Nim.
The example uses gme_open_file and not gme_load_file, and the former constructs the Music_Emu object on the C side for you. So you don't actually need (and shouldn't do) object construction on the Nim side.