【问题标题】:How to set C compiler in defsystem?如何在 defsystem 中设置 C 编译器?
【发布时间】:2013-11-21 13:58:40
【问题描述】:

我正在尝试使用quicklisp 加载cl-mpi 系统。这是系统定义:

(asdf:defsystem cl-mpi
    :description "Common Lisp bindings for the Message Passing Interface (MPI)"
    :author "Alex Fukunaga"
    :version "0.1.0"
    :license "MIT"
    :depends-on (:cffi :cffi-grovel)
    :components
    ((:file "packages")
     (:file "cl-mpi-configure" :depends-on ("packages"))
     (cffi-grovel:grovel-file "mpi-grovel" :depends-on ("packages" "cl-mpi-configure"))
     (:file "mpi" :depends-on ("packages"))))

这无法编译,因为它“不知道”$CC 的设置。我需要将其设置为mpicc。我找到了代码,我认为它是在哪里设置的:

(defun cc-compile-and-link (input-file output-file &key library)
  (let ((arglist
         `(,(or (getenv "CC") *cc*)
           ,@*cpu-word-size-flags*
           ,@*cc-flags*
           ;; add the cffi directory to the include path to make common.h visible
           ,(format nil "-I~A"
                    (directory-namestring
                     (truename
                      (asdf:system-definition-pathname :cffi-grovel))))
           ,@(when library *platform-library-flags*)
           "-o" ,(native-namestring output-file)
           ,(native-namestring input-file))))
    (when library
      ;; if it's a library that may be used, remove it
      ;; so we won't possibly be overwriting the code of any existing process
      (ignore-some-conditions (file-error)
        (delete-file output-file)))
    (apply #'invoke arglist)))

以上内容在asdf 包内。但是我不明白如何更改 defsystem 以考虑编译器。

PS:这是错误的样子:

External process exited with code 1.
Command was: "cc" "-m64" "-I/home/wvxvw/quicklisp/dists/quicklisp/software/cffi_0.11.1/" 
"-o" "/home/wvxvw/.cache/common-lisp/sbcl-1.1.2-1.fc18-linux-x64/home/wvxvw/quicklisp/local-projects/cl-mpi/mpi-grovel" 
"/home/wvxvw/.cache/common-lisp/sbcl-1.1.2-1.fc18-linux-x64/home/wvxvw/quicklisp/local-projects/cl-mpi/mpi-grovel.c"

Output was:
/home/wvxvw/.cache/common-lisp/sbcl-1.1.2-1.fc18-linux-x64/home/wvxvw/quicklisp/local-projects/cl-mpi/mpi-grovel.c:6:34: 
fatal error: /usr/include/mpi/mpi.h: No such file or directory

compilation terminated.

为便于阅读而格式化。编译器找不到标头,因为它不是正确的编译器(mpicc“知道”在哪里寻找 mpi.h 标头,它不会在 /usr/include 中寻找)。


很抱歉给您带来了困惑。我可以将$CC 设置为mpicc,但它仍然找不到/usr/include/mpich-x86_64/mpi.h 标头-所以也许我需要设置包含路径而不是编译器?如果有,怎么做?

这就是我设法将其设置为mpicc

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :cffi-grovel)
  (setf cffi-grovel::*cc* "mpicc"))

defsystem之前

编辑:哎呀,是 cffi 生成了错误的包含 :( 看起来像这样:

#include </usr/include/mpi/mpi.h>

代替:

#include "mpi.h"

有什么办法可以解决吗?


应用大量的骇客和诡计我可以让它工作。看来库的路径是在代码本身中设置的,所以我不得不

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :cffi-grovel)
  (setf cffi-grovel::*cc* "mpicc"
        mpi::*mpi-header-file* "/usr/include/mpich-x86_64/mpi.h"))

我还必须对我的系统进行一些更改才能编译整个系统。

但是,如果可能的话,我希望这个问题得到一般性的回答!即,以通用且可接受的方式设置 C 编译器及其选项的方法是什么?

【问题讨论】:

  • 标签compiler 应用于有关编译器编程的问题或有关编译器详细内部工作的问题。不要使用compiler 询问有关特定编译器的选项和设置的问题,请改用您感兴趣的编译器的名称。

标签: common-lisp cc cffi


【解决方案1】:

cl-mpi 包含一个名为“cl-mpi-configure.lisp”的文件。该文件看起来像是要更改为配置 cl-mpi 以使用正确的系统路径。

特别是这一行:

(defvar *mpi-header-file* "/usr/include/mpi/mpi.h") ; this is where  ubuntu apt-get install puts mpi.h. 

定义 mpi 头文件的路径。您需要更改此行以在系统上使用 mpi.h 的路径。这有点烦人,因为您不需要使用本地版本,而不是直接从 quicklisp 下载。

或者,您可以制作一个补丁来更智能地确定路径(例如使用pkg-config),然后向上游提交。

【讨论】:

  • 在 quicklisp 或其他相关位中安装一个包的通用机制不是更好吗,也许是在 asdf 土地上,这将允许覆盖将这些东西作为某些路径前缀查找的地方?这似乎比一个一个地修补软件包要好。
  • CFFI 使用 pkg-config 提供。但 mpi 包不使用该功能。
猜你喜欢
  • 1970-01-01
  • 2013-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-06
  • 1970-01-01
  • 2022-12-10
  • 1970-01-01
相关资源
最近更新 更多