chez scheme - 基于平台

时间:2016-10-10 23:32:16

标签: scheme chez-scheme

OpenGL library for Chez Scheme(目前仅适用于Linux)按如下方式加载GLUT库:

(define no-op (load-shared-object "libglut.so.3"))

这是该代码的link

当然,我们希望该库在Linux上加载libglut.so.3,但在macOS上加载GLUT.framework/GLUT

以下是Ypsilon Scheme如何基于平台加载库的示例:

(define libGLUT
  (cond
    (on-darwin  (load-shared-object "GLUT.framework/GLUT"))
    (on-windows (load-shared-object "glut32.dll"))
    (on-linux   (load-shared-object "libglut.so.3"))
    (on-freebsd (load-shared-object "libglut.so"))
    (on-openbsd (begin
             (load-shared-object "libXmu.so.10.0")
             (load-shared-object "libGLU.so.7.0")
             (load-shared-object "libglut.so.3.7")))
    (else
     (assertion-violation
      #f
          "can not locate GLUT library, unknown operating system"))))

检查Chez Scheme平台的好方法是什么,以便我们可以在外部库的绑定中做类似的事情?

2 个答案:

答案 0 :(得分:2)

来自https://github.com/cisco/ChezScheme/blob/master/examples/socket.ss

(case (machine-type)
  [(i3le ti3le) (load-shared-object "libc.so.6")]
  [(i3osx ti3osx a6osx ta6osx) (load-shared-object "libc.dylib")]
  [else (load-shared-object "libc.so")])

使用meta-cond代替将为您提供稍微更高效的运行时行为,因为它将在编译时解析。

答案 1 :(得分:1)

(machine-type)怎么样?

~ % uname -m -p -r -s
Darwin 15.6.0 x86_64 i386
~ % chez
Chez Scheme Version 9.4.1
Copyright 1984-2016 Cisco Systems, Inc.

> (machine-type)
ta6osx