如何“从源"安装C ++依赖项在Mac OS上安装Python包? [英] How to install C++ dependencies "from source" for a Python package on Mac OS?

查看:65
本文介绍了如何“从源"安装C ++依赖项在Mac OS上安装Python包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个Github存储库,其中包含Python的绑定".对于我感兴趣的C ++库.README提供了有关如何在类似Linux的计算机上安装C ++库的大量信息,但没有有关如何在Mac OS上安装C ++库的信息.

There is a Github repo containing Python "bindings" for a C++ library that I am interested in playing with. The README has abundant information about how to install the C++ library on Linux like machines, but no information about how to do so with a mac OS.

我还提出了一个问题,要求自述文件的安装说明除Linux外还包括特定于Mac OS的安装.在该问题上没有任何活动.

I have also opened up an issue requesting the README installation instructions include mac OS-specific installs in addition to linux. There hasn't been any activity on that issue.

这是两个存储库:

由于无法通过Brew/pip/anaconda安装C ++软件包,因此我不确定该如何进行.

Since the C++ package isn't available for installing via Brew/pip/anaconda, I'm not sure how to get going.

我已经尝试过 ./configure make .没有 ./configure 文件.

I have tried ./configure, and make. There is no ./configure file.

要解决缺少 ./configure 的问题,请阅读一个名为 autoconf 的工具,该工具可能会为您生成 ./configure .我用 brew 安装了它,但是不确定要传递什么参数.这些文档很难理解:https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Making-configure-Scripts.html

To address the lack of ./configure, read about a tool called autoconf which supposedly generates ./configure for you. I installed it with brew, but am not sure what arguments to pass it. These docs were pretty hard to understand: https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Making-configure-Scripts.html

仅使用 make 会导致错误提示音: error:不支持的选项'-fopenmp'使我陷入了一个完全不同的兔子洞,这使我不得不向生成文件:

Just using make results in the error clang: error: unsupported option '-fopenmp'That sent me down a whole different rabbit hole which had me adding lines to the Makefile:

CPP = /usr/local/opt/llvm/bin/clang
CPPFLAGS = -I/usr/local/opt/llvm/include -fopenmp
LDFLAGS = -L/usr/local/opt/llvm/lib

omp_hello: omp_hello.c
    $(CPP) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

那感觉很危险,因为我不知道这些东西是什么意思.加上它导致了一个新错误: ***缺少分隔符.停止.

That felt dangerous because I have no idea what any of that stuff means. Plus it resulted in a new error: *** missing separator. Stop.

因此,我读到这可能是由于使用了"soft"标签,而不是硬"标签.可以使用 cat -e -t -v makefile_name 标识的标签.我找到了一条硬"字样的行.标签丢失(上面的缩进行)并插入了它.这导致了一个新的错误:

So then I read that's probably due to using "soft" tabs instead of "hard" tabs which can be identified using cat -e -t -v makefile_name. I found the one line where a "hard" tab was missing (the indented line above) and inserted it. This resulted in a new error:

make: *** No rule to make target `omp_hello.c', needed by `omp_hello'.  Stop.

接下来,根据Yang Yushi的建议和他的评论意见,我根据他的回答更改了第39行和第40行,并在 CXXFLAGS 变量中添加了一些其他文件的位置:

Next, following the advice of Yang Yushi and his follow on comments, I changed lines 39 and 40 according to his answer, plus added the locations of some additional files to the CXXFLAGS variable:

-I//opt/homebrew/Cellar/libomp/11.0.1/include 
-L/opt/homebrew/Cellar/libomp/11.0.1/lib

这使我更进一步.接下来,如此答案所述,OSX不喜欢该脚本的安装位置.因此,我在makefile中更改了这两行,这似乎决定了安装位置:

And this got me a little further. Next, OSX didn't like where this script was trying to install, as explained by this answer. So I changed these two lines in the makefile which seemed to dictate install location:

INSTALL_HEAD_DIR = $(DESTDIR)/usr/include/libspot
INSTALL_LIB_DIR = $(DESTDIR)/usr/lib

INSTALL_HEAD_DIR = $(DESTDIR)/usr/local/include/libspot
INSTALL_LIB_DIR = $(DESTDIR)/usr/local/lib

那确实使我走得更远.接下来,我在生成文件中的以下行遇到一个错误,抱怨平坦的 -t :

And that indeed got me a little farther. Next I ran into an error complaining about the flat -t at these lines in the makefile:

@install -t $(INSTALL_LIB_DIR) $(LIB_DIR)/*.so
@install -t $(INSTALL_HEAD_DIR) $(INC_DIR)/*.h

所以我删除了这些标志,然后导致了此错误:

So I deleted those flags, which then resulted in this error:

Checking the headers installation directory (/usr/local/include/libspot)
Checking the library installation directory (/usr/local/lib)
Installing the shared library (libspot.so)
install: /usr/local/lib: Inappropriate file type or format

我找不到关于它的阅读材料,也没有如何解决的线索.任何进一步的帮助表示赞赏.

For which I can find no reading material and have no clue how to fix. Any further assistance appreciated.

以下是我试图回答这个问题的SO和其他资源的列表:

Here's a list of SO and other resources I've perused trying to answer this question:

  • Enable OpenMP support in clang in Mac OS X (sierra & Mojave)
  • makefile error: make: *** No rule to make target `omp.h' ; with OpenMP
  • makefile:4: *** missing separator. Stop
  • http://www.idryman.org/blog/2016/03/10/autoconf-tutorial-1/
  • https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Making-configure-Scripts.html
  • https://developer.gnome.org/anjuta-build-tutorial/stable/create-autotools.html.en

我该如何进行.

如果您知道如何执行此操作,还可以对每个步骤背后的概念进行简要说明吗?我很乐于学习一些知识,而不仅仅是按正确的顺序复制和粘贴命令.

If you know how to do this, could you also include a brief explanation of the concepts behind each step? I'd be happy to learn a little instead of just copying and pasting commands in the right order.

推荐答案

使用Apple Clang编译C ++源代码

我下载了 prjoect(libspot),并在Mac上成功进行了编译.我在Makefile中更改了两行(第39和40行)以使其工作.(遵循此答案)

Compile the C++ source code with Apple Clang

I downloaded the prjoect (libspot) and successfully compiled it on my Mac. I change two lines (39 and 40) in the Makefile to make it work. (Following this answer)

CC = clang++  # change from g++ to default Apple clang
CXXFLAGS = -std=c++11 -Wall -pedantic -Xpreprocessor -fopenmp  -lomp  # additional flags

您应该通过键入带有正确"字样的 make 来获取二进制文件.生成文件.

You should get the binary file by just type make with a "correct" Makefile.

(如果您看到类似无法找到omp.h"的内容,请在 CXXFLAGS 中添加 -I/usr/local/opt/libomp/include .)

(If you see something like "cant find omp.h", add -I/usr/local/opt/libomp/include to the CXXFLAGS.)

更新后的问题描述中的错误消息

The error message in the updated question description

make:***没有规则创建目标 omp_hello.c',而 omp_hello'则需要此规则.停止.

make: *** No rule to make target omp_hello.c', needed by omp_hello'. Stop.

告诉我们文件 omp_hello.c 丢失.编写Makefile是为了将源代码 omp_hello.c 编译为可执行的二进制文件 omp_hello .如果我有C源文件( omp_hello.c ),Makefile将允许我通过键入以下内容进行编译

is telling us that the file omp_hello.c is missing. The Makefile is written to compile the source code omp_hello.c to an executable binary file omp_hello. If I have the C source file (omp_hello.c), the Makefile will allow me to compile by just typing

make

代替

/usr/local/opt/llvm/bin/clang \
-I/usr/local/opt/llvm/include -fopenmp \
-L/usr/local/opt/llvm/lib \
omp_hello.c -o omp_hello

这只是正常的编译过程,与Python无关.该错误消息表示缺少要编译的源代码( omp_hello.c ).

This is just a normal compile process, it has nothing to do with Python. The error message is saying the source code to be compiled (omp_hello.c) is missing.

看起来这是一个带有自定义Makefile的小项目.通常,您仅使用 make 编译代码.您收到的错误似乎表明缺少llvm.您可能要尝试按照此答案安装llvm.

It looks like this is a small project with custom Makefile. Normally you compile the code with just make. The error you got seems to suggest the lack of llvm. You may want to try install llvm following this answer.

这篇关于如何“从源"安装C ++依赖项在Mac OS上安装Python包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆