2017-04-14 28 views
0

所以,我想用Tsdl这里是我所做的:例外Dl.DL_error:未定义的符号:SDL_GetError

  • 我找不到SDL 2.0.5apt-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的lib是还是其他什么东西?


更新:

> 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

[email protected] ~/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 

[email protected] ~/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 
+0

'apt'包的名称是'libsdl2-dev'。 – RichouHunter

+0

是的,我知道,但版本是2.0.4。 – Lhooq

+0

它看起来像sdl lib无法找到。你能报告的输出:'ocamlobjinfo $(opam config var tsdl:lib)/tsdl.cmxa | grep Extra'和'sdl2-config --libs' –

回答

1

这似乎是tsdl中的一个小问题,请参阅此处以获取更多信息:https://github.com/dbuenzli/tsdl/issues/38

它固定在master中。正如笔者建议你可以(现在)这样做,因为一个临时的解决办法:

opam pin add tsdl --dev

编辑:由@dbuenzli指示低于这个固定在0.9.4这是它的方式OPAM。

+0

感谢@esl的帮助。你能不能补充一点,这是固定在0.9.4,它正在去opam回购https://github.com/ocaml/opam-repository/pull/9770(它可能需要一点时间来合并,因为我在清除tsdl软件包depext的同时, –