无法链接 gmp:找不到 -lgmp 的库

问题描述 投票:0回答:3

我正在尝试通过运行

 在 macOS BigSur(M1 芯片)上安装 
fastecdsa

(venv) $ pip3 install fastecdsa

即使我之前安装了

gmp

$ brew install gmp

无论我做什么都找不到库

    src/curve.h:4:10: fatal error: 'gmp.h' file not found
    #include "gmp.h"

虽然当我创建符号链接时错误发生了变化

ln -s /opt/homebrew/include/gmp.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

现在我明白了:

    ld: library not found for -lgmp
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1

我也尝试过:

  • 通过 env 传递路径
    CFLAGS
    LDFLAGS
    以及均通过全局 env 导出 (
    export CFLAGS=...
    )
LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib pip3 install fastecdsa
CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include pip3 install fastecdsa
  • xcode-select --install
  • 无休无止地
    brew uninstall gmp
    brew install gmp
    ,甚至
    brew reinstall gmp
    brew unlink gmp
  • 安装rosetta2
  • 关闭并再次打开

我无法将手指放在上面:(

gcc clang macos-big-sur gmp apple-m1
3个回答
1
投票

您现在可能已经解决了这个问题,但只是说我遇到了类似的问题,我的解决方案是告诉

ld
查看自制程序库路径。运行它/将其添加到
~/.profile
:

export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include

(在我的例子中,我不需要 INCLUDE_PATH,但看起来你可能需要!)

之后,也许你的Python命令就可以开始工作了!


0
投票

enter image description here

使用setup.py安装并修改setup.py为镜像


0
投票

以下是我在 Mac 上解决类似问题的方法。问题是

pip install fastecdsa

...
      In file included from src/curve.c:1:
      src/curve.h:4:10: fatal error: 'gmp.h' file not found
      #include "gmp.h"
               ^~~~~~~
      1 error generated.
      error: command '/usr/local/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for fastecdsa
Failed to build fastecdsa
ERROR: Could not build wheels for fastecdsa, which is required to install pyproject.toml-based projects

解决办法是

  1. 安装GMP
brew install gmp
  1. 如果您已安装 GMP,请确保已链接
brew link gmp

阅读警告。如果它告诉您重新链接,请重新链接。

Warning: Already linked: /usr/local/Cellar/gmp/6.3.0
To relink, run:
  brew unlink gmp && brew link gmp
  1. CFLAGS
    LDFLAGS
    以及上面的链接传递到
    pip install
CFLAGS=-I/usr/local/Cellar/gmp/6.3.0/include LDFLAGS=-L/usr/local/Cellar/gmp/6.3.0/lib pip install fastecdsa

问题是 - 确保 GMP 标头和库的路径正确。

就我而言,它们分别是

  • /usr/local/Cellar/gmp/6.3.0/include
  • /usr/local/Cellar/gmp/6.3.0/lib

如果您 cd 进入头目录,您应该会在那里看到

gmp.h
。如果您 cd 进入 lib 目录,您应该会看到
libgmp.a
libgmp.dylib

© www.soinside.com 2019 - 2024. All rights reserved.