exception Dl.DL_error : undefined symbol: SDL_GetError
exception Dl.DL_error : undefined symbol: SDL_GetError
所以,我想使用 Tsdl
,这就是我所做的:
- 我找不到
SDL 2.0.5
和 apt-get
所以我下载了它,./configure && make && sudo make install
opam install tsdl
然后我创建了一个文件 main.ml
(在 tsdl website 上作为示例给出):
open Tsdl
open Result
let main () = match Sdl.init Sdl.Init.video with
| Error (`Msg e) -> Sdl.log "Init error: %s" e; exit 1
| Ok () ->
match Sdl.create_window ~w:640 ~h:480 "SDL OpenGL" Sdl.Window.opengl with
| Error (`Msg e) -> Sdl.log "Create window error: %s" e; exit 1
| Ok w ->
Sdl.delay 3000l;
Sdl.destroy_window w;
Sdl.quit ();
exit 0
let () = main ()
ocamlfind ocamlopt -package tsdl -linkpkg -o main.native main.ml
它有效,现在我的问题来了:
./main.native
Fatal error: exception Dl.DL_error("./main.native: undefined symbol: SDL_GetError")
我是不是做错了什么,或者我是否需要明确告诉我的 SDL2 库在哪里或其他什么地方?
更新:
> ocamlobjinfo $(opam config var tsdl:lib)/tsdl.cmxa | grep Extra
Extra C object files: -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2 -ltsdl
Extra C options:
> sdl2-config --libs
-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2
更新 2:
> ldd ./main.native
linux-vdso.so.1 => (0x00007fff1f4c1000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f4aff55e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4aff255000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4aff050000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4afec87000)
/lib64/ld-linux-x86-64.so.2 (0x000055dc05e17000)
更新 3
lhooq@lhooq ~/tsdl $ ocamlfind ocamlopt -cclib -lSDL2 -package tsdl -linkpkg -o min.native min.ml -verbose
Effective set of compiler predicates: pkg_result,pkg_unix,pkg_bigarray,pkg_str,pkg_bytes,pkg_ctypes,pkg_ctypes.foreign.base,pkg_ctypes.foreign.unthreaded,pkg_ctypes.foreign,pkg_tsdl,autolink,native
+ ocamlopt.opt -o min.native -verbose -I /home/lhooq/.opam/4.04.0/lib/result -I /home/lhooq/.opam/4.04.0/lib/bytes -I /home/lhooq/.opam/4.04.0/lib/ctypes -I /home/lhooq/.opam/4.04.0/lib/tsdl /home/lhooq/.opam/4.04.0/lib/result/result.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/unix.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/str.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.cmxa /home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.cmxa -cclib -lSDL2 min.ml
+ as -o 'min.o' '/tmp/camlasm9ab424.s'
+ as -o '/tmp/camlstartupe796c9.o' '/tmp/camlstartup4a1081.s'
+ gcc -o 'min.native' '-L/home/lhooq/.opam/4.04.0/lib/result' '-L/home/lhooq/.opam/4.04.0/lib/bytes' '-L/home/lhooq/.opam/4.04.0/lib/ctypes' '-L/home/lhooq/.opam/4.04.0/lib/tsdl' '-L/home/lhooq/.opam/4.04.0/lib/ocaml' '/tmp/camlstartupe796c9.o' '/home/lhooq/.opam/4.04.0/lib/ocaml/std_exit.o' 'min.o' '/home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/str.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/unix.a' '/home/lhooq/.opam/4.04.0/lib/result/result.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/stdlib.a' '-L/usr/local/lib' '-Wl,-rpath,/usr/local/lib' '-Wl,--enable-new-dtags' '-lSDL2' '-ltsdl' '-Wl,--no-as-needed' '-lffi' '-lctypes-foreign-base_stubs' '-Wl,--no-as-needed' '-lffi' '-lctypes_stubs' '-Wl,--no-as-needed' '-lcamlstr' '-lbigarray' '-lunix' '-lSDL2' '/home/lhooq/.opam/4.04.0/lib/ocaml/libasmrun.a' -lm -ldl
lhooq@lhooq ~/tsdl $ ocamlfind ocamlopt -package tsdl -linkpkg -o min.native min.ml -verbose
Effective set of compiler predicates: pkg_result,pkg_unix,pkg_bigarray,pkg_str,pkg_bytes,pkg_ctypes,pkg_ctypes.foreign.base,pkg_ctypes.foreign.unthreaded,pkg_ctypes.foreign,pkg_tsdl,autolink,native
+ ocamlopt.opt -o min.native -verbose -I /home/lhooq/.opam/4.04.0/lib/result -I /home/lhooq/.opam/4.04.0/lib/bytes -I /home/lhooq/.opam/4.04.0/lib/ctypes -I /home/lhooq/.opam/4.04.0/lib/tsdl /home/lhooq/.opam/4.04.0/lib/result/result.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/unix.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/str.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.cmxa /home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.cmxa min.ml
+ as -o 'min.o' '/tmp/camlasm201bd8.s'
+ as -o '/tmp/camlstartup7113e2.o' '/tmp/camlstartup4724f2.s'
+ gcc -o 'min.native' '-L/home/lhooq/.opam/4.04.0/lib/result' '-L/home/lhooq/.opam/4.04.0/lib/bytes' '-L/home/lhooq/.opam/4.04.0/lib/ctypes' '-L/home/lhooq/.opam/4.04.0/lib/tsdl' '-L/home/lhooq/.opam/4.04.0/lib/ocaml' '/tmp/camlstartup7113e2.o' '/home/lhooq/.opam/4.04.0/lib/ocaml/std_exit.o' 'min.o' '/home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/str.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/unix.a' '/home/lhooq/.opam/4.04.0/lib/result/result.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/stdlib.a' '-L/usr/local/lib' '-Wl,-rpath,/usr/local/lib' '-Wl,--enable-new-dtags' '-lSDL2' '-ltsdl' '-Wl,--no-as-needed' '-lffi' '-lctypes-foreign-base_stubs' '-Wl,--no-as-needed' '-lffi' '-lctypes_stubs' '-Wl,--no-as-needed' '-lcamlstr' '-lbigarray' '-lunix' '/home/lhooq/.opam/4.04.0/lib/ocaml/libasmrun.a' -lm -ldl
这似乎是 tsdl 中的一个小问题,有关详细信息,请参阅:https://github.com/dbuenzli/tsdl/issues/38
在master中是固定的。正如作者建议的那样,您可以(暂时)将此作为临时修复:
opam pin add tsdl --dev
编辑:正如下面@dbuenzli 所指出的,这已在 0.9.4 中得到修复,该版本正在走向 opam。
所以,我想使用 Tsdl
,这就是我所做的:
- 我找不到
SDL 2.0.5
和apt-get
所以我下载了它,./configure && make && sudo make install
opam install tsdl
然后我创建了一个文件
main.ml
(在 tsdl website 上作为示例给出):open Tsdl open Result let main () = match Sdl.init Sdl.Init.video with | Error (`Msg e) -> Sdl.log "Init error: %s" e; exit 1 | Ok () -> match Sdl.create_window ~w:640 ~h:480 "SDL OpenGL" Sdl.Window.opengl with | Error (`Msg e) -> Sdl.log "Create window error: %s" e; exit 1 | Ok w -> Sdl.delay 3000l; Sdl.destroy_window w; Sdl.quit (); exit 0 let () = main ()
ocamlfind ocamlopt -package tsdl -linkpkg -o main.native main.ml
它有效,现在我的问题来了:
./main.native
Fatal error: exception Dl.DL_error("./main.native: undefined symbol: SDL_GetError")
我是不是做错了什么,或者我是否需要明确告诉我的 SDL2 库在哪里或其他什么地方?
更新:
> ocamlobjinfo $(opam config var tsdl:lib)/tsdl.cmxa | grep Extra
Extra C object files: -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2 -ltsdl
Extra C options:
> sdl2-config --libs
-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2
更新 2:
> ldd ./main.native
linux-vdso.so.1 => (0x00007fff1f4c1000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f4aff55e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4aff255000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4aff050000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4afec87000)
/lib64/ld-linux-x86-64.so.2 (0x000055dc05e17000)
更新 3
lhooq@lhooq ~/tsdl $ ocamlfind ocamlopt -cclib -lSDL2 -package tsdl -linkpkg -o min.native min.ml -verbose
Effective set of compiler predicates: pkg_result,pkg_unix,pkg_bigarray,pkg_str,pkg_bytes,pkg_ctypes,pkg_ctypes.foreign.base,pkg_ctypes.foreign.unthreaded,pkg_ctypes.foreign,pkg_tsdl,autolink,native
+ ocamlopt.opt -o min.native -verbose -I /home/lhooq/.opam/4.04.0/lib/result -I /home/lhooq/.opam/4.04.0/lib/bytes -I /home/lhooq/.opam/4.04.0/lib/ctypes -I /home/lhooq/.opam/4.04.0/lib/tsdl /home/lhooq/.opam/4.04.0/lib/result/result.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/unix.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/str.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.cmxa /home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.cmxa -cclib -lSDL2 min.ml
+ as -o 'min.o' '/tmp/camlasm9ab424.s'
+ as -o '/tmp/camlstartupe796c9.o' '/tmp/camlstartup4a1081.s'
+ gcc -o 'min.native' '-L/home/lhooq/.opam/4.04.0/lib/result' '-L/home/lhooq/.opam/4.04.0/lib/bytes' '-L/home/lhooq/.opam/4.04.0/lib/ctypes' '-L/home/lhooq/.opam/4.04.0/lib/tsdl' '-L/home/lhooq/.opam/4.04.0/lib/ocaml' '/tmp/camlstartupe796c9.o' '/home/lhooq/.opam/4.04.0/lib/ocaml/std_exit.o' 'min.o' '/home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/str.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/unix.a' '/home/lhooq/.opam/4.04.0/lib/result/result.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/stdlib.a' '-L/usr/local/lib' '-Wl,-rpath,/usr/local/lib' '-Wl,--enable-new-dtags' '-lSDL2' '-ltsdl' '-Wl,--no-as-needed' '-lffi' '-lctypes-foreign-base_stubs' '-Wl,--no-as-needed' '-lffi' '-lctypes_stubs' '-Wl,--no-as-needed' '-lcamlstr' '-lbigarray' '-lunix' '-lSDL2' '/home/lhooq/.opam/4.04.0/lib/ocaml/libasmrun.a' -lm -ldl
lhooq@lhooq ~/tsdl $ ocamlfind ocamlopt -package tsdl -linkpkg -o min.native min.ml -verbose
Effective set of compiler predicates: pkg_result,pkg_unix,pkg_bigarray,pkg_str,pkg_bytes,pkg_ctypes,pkg_ctypes.foreign.base,pkg_ctypes.foreign.unthreaded,pkg_ctypes.foreign,pkg_tsdl,autolink,native
+ ocamlopt.opt -o min.native -verbose -I /home/lhooq/.opam/4.04.0/lib/result -I /home/lhooq/.opam/4.04.0/lib/bytes -I /home/lhooq/.opam/4.04.0/lib/ctypes -I /home/lhooq/.opam/4.04.0/lib/tsdl /home/lhooq/.opam/4.04.0/lib/result/result.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/unix.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.cmxa /home/lhooq/.opam/4.04.0/lib/ocaml/str.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.cmxa /home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.cmxa /home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.cmxa min.ml
+ as -o 'min.o' '/tmp/camlasm201bd8.s'
+ as -o '/tmp/camlstartup7113e2.o' '/tmp/camlstartup4724f2.s'
+ gcc -o 'min.native' '-L/home/lhooq/.opam/4.04.0/lib/result' '-L/home/lhooq/.opam/4.04.0/lib/bytes' '-L/home/lhooq/.opam/4.04.0/lib/ctypes' '-L/home/lhooq/.opam/4.04.0/lib/tsdl' '-L/home/lhooq/.opam/4.04.0/lib/ocaml' '/tmp/camlstartup7113e2.o' '/home/lhooq/.opam/4.04.0/lib/ocaml/std_exit.o' 'min.o' '/home/lhooq/.opam/4.04.0/lib/tsdl/tsdl.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-unthreaded.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes-foreign-base.a' '/home/lhooq/.opam/4.04.0/lib/ctypes/ctypes.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/str.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/bigarray.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/unix.a' '/home/lhooq/.opam/4.04.0/lib/result/result.a' '/home/lhooq/.opam/4.04.0/lib/ocaml/stdlib.a' '-L/usr/local/lib' '-Wl,-rpath,/usr/local/lib' '-Wl,--enable-new-dtags' '-lSDL2' '-ltsdl' '-Wl,--no-as-needed' '-lffi' '-lctypes-foreign-base_stubs' '-Wl,--no-as-needed' '-lffi' '-lctypes_stubs' '-Wl,--no-as-needed' '-lcamlstr' '-lbigarray' '-lunix' '/home/lhooq/.opam/4.04.0/lib/ocaml/libasmrun.a' -lm -ldl
这似乎是 tsdl 中的一个小问题,有关详细信息,请参阅:https://github.com/dbuenzli/tsdl/issues/38
在master中是固定的。正如作者建议的那样,您可以(暂时)将此作为临时修复:
opam pin add tsdl --dev
编辑:正如下面@dbuenzli 所指出的,这已在 0.9.4 中得到修复,该版本正在走向 opam。