gpt4 book ai didi

ocaml - fatal error : exception Graphics. Graphic_failure ("Cannot open display ")

转载 作者:行者123 更新时间:2023-12-05 02:58:58 25 4
gpt4 key购买 nike

我试图运行代码,但它一直显示相同的错误。我首先使用 ocamlc -o cardioide graphics.cma cardioide.ml 进行编译,它似乎可以工作,但随后我执行 ./cardioide 来执行它,并出现消息 Fatal error: exception Graphics.Graphic_failure("Cannot open display ") 。 ..我在整个互联网上搜索过,但找不到解决方案,有人可以帮助我吗?

谢谢

open Graphics

let () = open_graph "300x20"

let () =
moveto 200 150;
for i = 0 to 200 do
let th = atan 1. *. float i /. 25. in
let r = 50. *. (1. -. sin th) in
lineto (150 + truncate (r *. cos th))
(150 + truncate (r *. sin th))
done;

ignore (read_key ())

错误信息:

 Fatal error: exception Graphics.Graphic_failure("Cannot open display ")

最佳答案

open_graph 函数的字符串参数不是大小或标题,而是传递给底层图形子系统的与实现相关的信息(在 X11 中是屏幕编号)。在现代 OCaml 中,可选参数是使用标签传递的,但是 Graphics 是在将此功能引入该语言之前很久就编写的。因此,您必须在那里传递一个空字符串(如果您不想传递任何特定于底层图形子系统信息的实现),例如,

open_graph ""

将以独立于系统的方式为您完成工作。

此外,如果您想调整窗口大小,则可以使用resize_window 函数。要设置标题,请使用 set_window_title

作为历史引用,传递给 open_graph 的字符串参数具有以下语法(不再记录,因此没有理由相信它会得到遵守):

Here are the graphics mode specifications supported by Graphics.open_graph on the X11 implementation of this library: the argument to Graphics.open_graph has the format "display-name geometry", where display-name is the name of the X-windows display to connect to, and geometry is a standard X-windows geometry specification. The two components are separated by a space. Either can be omitted, or both. Examples:

Graphics.open_graph "foo:0"  connects to the display foo:0 and creates a
window with the default geometry
Graphics.open_graph "foo:0 300x100+50-0" connects to the display foo:0 and
creates a window 300 pixels wide by 100 pixels tall, at location (50,0)
Graphics.open_graph " 300x100+50-0" connects to the default display and
creates a window 300 pixels wide by 100 pixels tall, at location (50,0)
Graphics.open_graph "" connects to the default display and creates a
window with the default geometry.

关于ocaml - fatal error : exception Graphics. Graphic_failure ("Cannot open display "),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58437129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com