0

I try to compile a Nim project that uses SDL2 Image with Emscripten, but I get several conflicting types errors. I could reproduce this issue in this small code snippet:

index.nim

import sdl2, sdl2.image

const imgFlags: cint = IMG_INIT_PNG
if image.init(imgFlags) != imgFlags:
  raise Exception.newException(
    "SDL2 Image initialization failed, SDL error: " & $getError())

nim.cfg

@if emscripten:
  define = SDL_Static
  gc = none
  cc = clang
  clang.exe = "emcc"
  clang.linkerexe = "emcc"
  clang.options.linker = ""
  cpu = "i386"
  out = "index.html"
  warning[GcMem] = off
  passC = "-Wno-warn-absolute-paths -I/path/to/SDL2/headers"
  passL = "-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='[\"png\"]'"
@end

When I compile this code snippet, I get an error: conflicting types

$ nim c -d:emscripten index.nim
Hint: used config file '/path/to/Nim/config/nim.cfg' [Conf]
Hint: used config file '/path/to/my-project/nim.cfg' [Conf]
Hint: system [Processing]
Hint: index [Processing]
Hint: sdl2 [Processing]
Hint: macros [Processing]
Hint: unsigned [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
SDL2 will be statically linked. Please make sure you pass the correct linker flags (library search paths, linked libraries).
Hint: image [Processing]
CC: index
Error: execution of an external compiler program 'emcc -c -w -Wno-warn-absolute-paths -Iinclude  -I/path/to/Nim/lib -o /path/to/my-project/nimcache/index.o /path/to/my-project/nimcache/index.c' failed with exit code: 1

/path/to/my-project/nimcache/index.c:65:21: error: conflicting types for 'SDL_GetError'
N_NIMCALL(NCSTRING, SDL_GetError)(void);
                    ^
/path/to/SDL2/SDL_error.h:42:37: note: previous declaration is here
extern DECLSPEC const char *SDLCALL SDL_GetError(void);
                                    ^

Have I misconfigured something? How can I fix it?

Edit: I don't get this errors if I remove define = SDL_Static from nim.cfg, but if I do that, I can not static link to SDL.


Nim Compiler Version 0.16.1 (2017-05-07) [Linux: amd64] (latest version of devel branch)

emcc (Emscripten gcc/clang-like replacement) 1.37.9 (commit b5bee629cb54864e7e231ae55a7d0ae9bdc25c6c)

maiermic
  • 4,764
  • 6
  • 38
  • 77
  • 2
    Looks like sdl2.image.nim module has a bug. This issue should likely be reproduced when compiling to normal native target. If that is so, report the issue to nim-lang/sdl2 project. – uran May 09 '17 at 07:50
  • It compiles without errors if I run `nim c index.nim` (no `-d:emscripten`). – maiermic May 09 '17 at 07:57

1 Answers1

1

It is a bug that is fixed by this pull request. It should be released in version 1.2 of package sdl2. Till then you can install the latest (development) version from the repository:

nimble install sdl2#head

To link statically pass --dynlibOverride:SDL2 to the Nim compiler.

maiermic
  • 4,764
  • 6
  • 38
  • 77