gmp.h 文件在 Xcode、mac 中未找到错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22799435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:49:59  来源:igfitidea点击:

gmp.h file not found error in Xcode, mac

c++cxcodemacosgmp

提问by Q123

I downloaded gmp-6.0.0a.tar.xzfile and unzip(tar) in usr/localdirectory. As people said , I typed ./configure, make, make checkand sudo make installin the gmp-6.0.0directory. Installing seemed fine. But when i tried to test like this

我下载了gmp-6.0.0a.tar.xz文件并在usr/local目录中解压缩(tar)。随着人们说,我输入./configuremakemake checksudo make installgmp-6.0.0目录中。安装似乎没问题。但是当我尝试这样测试时

#include <stdio.h>
#include <gmp.h>
#include <gmpxx.h>


int main(int argc, const char * argv[])
{

    // insert code here...
    printf("Hello, World!\n");
    return 0;
}

it has error that gmp.hfile not found. I added -lgmpto Other Linker Flags but not works.

它有错误,gmp.h找不到文件。我添加-lgmp到其他链接器标志但不起作用。

I do not know how to deal with this kind of problem. Could anyone help?

我不知道如何处理这种问题。有人可以帮忙吗?



Thank you Dietrich Epp. Now I do not have a error of not gmp.h file found but I do have gmpxx.h file not found. I don't know why..

谢谢迪特里希·埃普。现在我没有找到 not gmp.h 文件的错误,但我确实没有找到 gmpxx.h 文件。我不知道为什么..

Any suggestion???

有什么建议???

采纳答案by Brett Hale

C++ support is notenabled by default when configuring GMP. Untar the package, and configure with: ./configure --prefix=/usr/local --enable-cxx- this will also install the gmpxx.hheader, and the libgmpxx.dyliband / or libgmpxx.alibraries

配置 GMP 时默认启用C++ 支持。解压包,并配置:./configure --prefix=/usr/local --enable-cxx- 这也将安装gmpxx.h头文件,和libgmpxx.dylib和/或libgmpxx.a

Not sure if the latest GMP picks up clang for the C++ compiler. You can manually set the environment variables, e.g., CC=clang(C99 default), and: CXX=clang++ -std=c++11 -stdlib=libc++(C++11 dialect - also passes C++11 options to the linker). Again, this might be unnecessary.

不确定最新的 GMP 是否为 C++ 编译器提供了叮当声。您可以手动设置环境变量,例如CC=clang(C99 默认)和:CXX=clang++ -std=c++11 -stdlib=libc++(C++11 方言 - 也将 C++11 选项传递给链接器)。同样,这可能是不必要的。

Your test, since it includes C++, must be built as a C++ application. Also, libgmpxx.dylibis itself linked to libgmp.dylib, so for a simple C++ test program:

您的测试,因为它包含 C++,所以必须构建为 C++ 应用程序。此外,libgmpxx.dylib本身链接到libgmp.dylib,因此对于一个简单的 C++ 测试程序:

$CXX -I/usr/local/include gmptest.cc -o gmptest -L/usr/local/lib -lgmpxx

should be sufficient.

应该足够了。

It may be necessary to prepend /usr/local/libto the DYLD_LIBRARY_PATHvariable, if other system GMP library installations are used first, unless you hardcode the library with the linker -rpathoption. But that's something to worry about if and when the problem arises.

如果首先使用其他系统 GMP 库安装,则可能需要/usr/local/libDYLD_LIBRARY_PATH变量前添加,除非您使用链接器-rpath选项对库进行硬编码。但是,如果问题出现以及何时出现,那就需要担心了。

回答by Dietrich Epp

First of all, you should not untar it in /usr/local. Just untar it somewhere in your home directory (it doesn't matter), then ./configure; make; make check; sudo make install.

首先,你不应该在/usr/local. 只需将它解压到您的主目录中的某个位置(没关系),然后./configure; make; make check; sudo make install.

Your problem may be caused by the compiler not searching /usr/local/include.

您的问题可能是由编译器未搜索引起的/usr/local/include

  1. Check that /usr/local/include/gmp.hexists. If it doesn't exist, GMP is installed incorrectly (or installed in a different location).

  2. Add -I/usr/local/includeto your compiler flags. In Xcode, this is done by adding /usr/local/includeto the "additional header search paths" in the project settings (or some setting like that).

  1. 检查是否/usr/local/include/gmp.h存在。如果不存在,则 GMP 安装不正确(或安装在其他位置)。

  2. 添加-I/usr/local/include到您的编译器标志。在 Xcode 中,这是通过添加/usr/local/include到项目设置(或类似设置)中的“附加标题搜索路径”来完成的。