在Windows 7上通过cgo使用SDL2安装软件包的问题

时间:2018-04-24 13:58:21

标签: go installation windows-7-x64 cgo

我在为golang安装SDL2时遇到问题 (使用Visual Studio代码)

尝试获取包裹:

"C:\Users\Bob\go\src\flappyGopher>go get -v github.com/veandco/go-sdl2/sdl
github.com/veandco/go-sdl2/sdl
# github.com/veandco/go-sdl2/sdl
In file included from ..\github.com\veandco\go-sdl2\sdl\audio.go:4:0:
./sdl_wrapper.h:2:23: fatal error: SDL2/SDL.h: No such file or directory
compilation terminated."

我使用了本手册:EarlyStopping is ignoring my custom metrics defined #10018

我还有env变量:

CGO_CFLAGS C:\MinGW64\mingw64\include
GOPATH C:\Users\Bob\go
GOROOT C:\Go\
PATH ... C:\MinGW64\mingw64\x86_64-w64-mingw32\bin;C:\MinGW64\mingw64\bin;C:\Users\Bob\Downloads\SDL2-2.0.8\x86_64-w64-mingw32\include\SDL2

编辑:gcc输出看起来像一团糟

C:\Users\Bob>gcc -xc -E -v -
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64-  mingw32 --e
nable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable
-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC -
-disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-d
ebug --enable-threads=posix --enable-version-specific-runtime-libs --enable-full
y-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-l
d --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm -
-with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://td
m-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm64-1)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 C:/Program Files/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/cc1.exe
 -E -quiet -v -iprefix C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-min
gw32/5.1.0/ -D_REENTRANT - -mtune=generic -march=x86-64
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/include"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/../../../../include"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/include-fixed"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/include
 C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../..
/include
 C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed
  C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../..
/x86_64-w64-mingw32/include
End of search list.

1 个答案:

答案 0 :(得分:0)

请参阅this

原因是go install试图编译一些 cgo github.com\veandco\go-sdl2包的代码,显然是那个代码 想要使用C header files libsdl2库¹。

你需要libsdl2 可供编译器使用。

找出C编译器期望找到include(header)的位置 文件,请参阅this

¹这就是C的作用方式。要在其他C代码中使用编译库,编译器 通常需要知道所提供的类型和功能的定义 通过那个图书馆。这些库的格式 - 与Go库相反 - 通常不会在其元数据中嵌入类型信息,因此编译器也是如此 需要从某个地方获取信息。在C和C ++世界中,这些信息通常保存在所谓的include(also:header)文件中 这包括 - 通过使用所谓的预处理器 - 两者都进入 用于构建库的代码和使用该库的代码。