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
gmp.h file not found error in Xcode, mac
提问by Q123
I downloaded gmp-6.0.0a.tar.xz
file and unzip(tar) in usr/local
directory.
As people said , I typed ./configure
, make
, make check
and sudo make install
in the gmp-6.0.0
directory.
Installing seemed fine. But when i tried to test like this
我下载了gmp-6.0.0a.tar.xz
文件并在usr/local
目录中解压缩(tar)。随着人们说,我输入./configure
,make
,make check
和sudo make install
在gmp-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.h
file not found.
I added -lgmp
to 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.h
header, and the libgmpxx.dylib
and / or libgmpxx.a
libraries
配置 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.dylib
is 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/lib
to the DYLD_LIBRARY_PATH
variable, if other system GMP library installations are used first, unless you hardcode the library with the linker -rpath
option. But that's something to worry about if and when the problem arises.
如果首先使用其他系统 GMP 库安装,则可能需要/usr/local/lib
在DYLD_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
。
Check that
/usr/local/include/gmp.h
exists. If it doesn't exist, GMP is installed incorrectly (or installed in a different location).Add
-I/usr/local/include
to your compiler flags. In Xcode, this is done by adding/usr/local/include
to the "additional header search paths" in the project settings (or some setting like that).
检查是否
/usr/local/include/gmp.h
存在。如果不存在,则 GMP 安装不正确(或安装在其他位置)。添加
-I/usr/local/include
到您的编译器标志。在 Xcode 中,这是通过添加/usr/local/include
到项目设置(或类似设置)中的“附加标题搜索路径”来完成的。