Chez基于平台的负载共享对象



Chez Scheme的OpenGL库(目前仅为Linux设置)如下加载GLUT库:

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

这是该代码的链接。

当然,我们希望库在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上检查平台的好方法是什么,以便我们可以在对外部库的绑定中做类似的事情?

From 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将给你稍微更有效的运行时行为,因为它将在编译时解决。

(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

相关内容

  • 没有找到相关文章

最新更新