【问题标题】:conflicting types when compiling Nim and SDL2 Image with Emscripten使用 Emscripten 编译 Nim 和 SDL2 图像时的类型冲突
【发布时间】:2017-05-08 19:16:24
【问题描述】:

我尝试编译一个将 SDL2 Image 与 Emscripten 结合使用的 Nim 项目,但我遇到了几个 冲突类型 错误。我可以在这个小代码 sn-p 中重现这个问题:

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

当我编译这段代码 sn-p 时,我得到一个错误:冲突类型

$ 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);
                                    ^

我是否配置错误?我该如何解决?

编辑:如果我从 nim.cfg 中删除 define = SDL_Static,我不会收到此错误,但如果我这样做,我无法静态链接到 SDL .


Nim 编译器版本 0.16.1 (2017-05-07) [Linux: amd64](devel 分支的最新版本)

emcc(Emscripten gcc/clang-like 替换)1.37.9(提交 b5bee629cb54864e7e231ae55a7d0ae9bdc25c6c)

【问题讨论】:

  • 看起来 sdl2.image.nim 模块有错误。编译为正常的本机目标时,应该可能会重现此问题。如果是这样,请将问题报告给 nim-lang/sdl2 项目。
  • 如果我运行nim c index.nim(没有-d:emscripten),它编译不会出错。

标签: c sdl-2 emscripten nim-lang sdl-image


【解决方案1】:

这是一个由this 拉取请求修复的bug。它应该在 sdl2 包的 1.2 版中发布。在此之前,您可以从存储库安装最新(开发)版本:

nimble install sdl2#head

--dynlibOverride:SDL2 静态链接传递给 Nim 编译器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多