首页 > 解决方案 > 在 FreeBSD 12 和 Debian 10 上编译 c2ffi 的困难

问题描述

我在 FreeBSD 12 和 Debian 10 上安装 c2ffi ( https://github.com/rpav/c2ffi ) 时遇到问题。我需要 c2ffi 才能使用一些依赖 c2ffi 的 Common Lisp 绑定。

在 FreeBSD 12 上,我同时安装了 Clang 6.0(默认)和 10.0;c2ffi 需要 LLVM 10.0。因为 cc 和 c++ 在我的 FreeBSD 安装中引用了 Clang 6.0,所以我设置PATH/usr/local/llvm10/bin:$PATH,并且我还设置了别名来引用clangand clang++。我安装了 cmake 版本 3.17.3。但是,当我进入make安装 c2ffi 的阶段时,我遇到了以下错误:

Scanning dependencies of target c2ffi
[  7%] Building CXX object CMakeFiles/c2ffi.dir/src/AST.cpp.o
[ 15%] Building CXX object CMakeFiles/c2ffi.dir/src/Decl.cpp.o
[ 23%] Building CXX object CMakeFiles/c2ffi.dir/src/Expr.cpp.o
[ 30%] Building CXX object CMakeFiles/c2ffi.dir/src/OutputDriver.cpp.o
[ 38%] Building CXX object CMakeFiles/c2ffi.dir/src/Template.cpp.o
[ 46%] Building CXX object CMakeFiles/c2ffi.dir/src/Type.cpp.o
[ 53%] Building CXX object CMakeFiles/c2ffi.dir/src/c2ffi.cpp.o
[ 61%] Building CXX object CMakeFiles/c2ffi.dir/src/drivers/JSON.cpp.o
/home/michael/c2ffi/src/drivers/JSON.cpp:36:26: warning: passing an object that
      undergoes default argument promotion to 'va_start' has undefined behavior
      [-Wvarargs]
            va_start(ap, close);
                         ^
/home/michael/c2ffi/src/drivers/JSON.cpp:32:61: note: parameter of type 'bool'
      is declared here
        void write_object(const char *type, bool open, bool close, ...) {
                                                            ^
1 warning generated.
[ 69%] Building CXX object CMakeFiles/c2ffi.dir/src/drivers/Null.cpp.o
[ 76%] Building CXX object CMakeFiles/c2ffi.dir/src/drivers/Sexp.cpp.o
[ 84%] Building CXX object CMakeFiles/c2ffi.dir/src/init.cpp.o
[ 92%] Building CXX object CMakeFiles/c2ffi.dir/src/options.cpp.o
[100%] Linking CXX executable bin/c2ffi
/usr/bin/ld: error: unable to find library -lclang-cpp
c++: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[2]: stopped in /usr/home/michael/c2ffi/build
*** Error code 1

Stop.
make[1]: stopped in /usr/home/michael/c2ffi/build
*** Error code 1

Stop.
make: stopped in /usr/home/michael/c2ffi/build

该文件libclang-cpp.so存在于我的/usr/local/llvm10/lib目录中,但 cmake 未检测到它。我尝试了各种其他方法,包括设置LD_LIBRARY_PATHCMAKE_LIBRARY_PATH环境变量,但无济于事;我收到与上述相同的错误消息。

我放弃了在 FreeBSD 上安装 c2ffi,并尝试在带有 LLVM 10.0 和 cmake 3.18.1 的全新安装的 Debian 10 上安装它。但是,当我make在 Debian 上运行时,我得到了以下错误消息:

[  7%] Building CXX object CMakeFiles/c2ffi.dir/src/AST.cpp.o
/home/michael/c2ffi/src/AST.cpp:24:10: fatal error: 'clang/AST/ASTConsumer.h' file not found
#include <clang/AST/ASTConsumer.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/c2ffi.dir/build.make:82: CMakeFiles/c2ffi.dir/src/AST.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:123: CMakeFiles/c2ffi.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

我想知道如何在我的 FreeBSD 和 Debian 系统上构建 c2ffi?

标签: cmakecommon-lisp

解决方案


在我的 FreeBSD 安装中,我在 CMakeLists.txt 中替换了该行

target_link_libraries(c2ffi PUBLIC clang-cpp LLVM)

target_link_libraries(c2ffi PUBLIC /usr/local/llvm10/lib/libclang-cpp.so LLVM)

在我的 Debian 安装中,我发现我没有安装 libclang 开发包之一。安装该软件包后,我可以make毫无问题地运行。


推荐阅读