【问题标题】:Xcode Version 6.0.1 gmp.h header file not found, even though gmp.h and gmpxx.h are in local/includeXcode 6.0.1 版 gmp.h 头文件未找到,即使 gmp.h 和 gmpxx.h 在本地/包含中
【发布时间】:2014-11-03 10:49:13
【问题描述】:

我正在尝试让 GMP 与 Xcode 一起工作。到目前为止,我已经解开了主目录中的文件,运行了所有必要的命令来对其进行配置、制作和安装

./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install

gmp.h 和 gmpxx.h 都在 usr/local/include 中,但是在尝试包含文件时我仍然遇到错误。我相信我需要添加一个编译器标志,但是对于这个版本的 Xcode,我不知道该怎么做。如果不是这种情况,我需要做其他事情,请提出建议,我将非常感激。

我的代码如下所示:

#include <iostream>
#include <gmp.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

我可以在 c++ 中使用 GMP 进行编码吗?还是我需要c中的代码?任何帮助使它工作将非常感谢,在此先感谢一吨!

很抱歉,如果这似乎是一个重复的问题,我确实查看了其他问题,但我无法按照之前问题的答案让它工作。

更新

在 Xcode 中添加了 libgmp.la 和 libgmpxx.la,还添加了 /usr/local/include 到头文件搜索中,但仍然无法正常工作!我在我的项目中看到了库文件,如果我放了“gmp.h”而不是它可以工作,但是当我去使用 GMP 时,它无法告诉我将其他 GMP 文件中的更改为“gmp.h”,这似乎不是正确的。

有什么想法吗?

【问题讨论】:

  • 您可能需要以某种方式添加-I/usr/local/include 开关以指定自定义包含路径。我对 Xcode 不熟悉,但应该有“附加头文件路径”之类的东西。
  • 我认为可能是这样,我非常认为你是正确的。我一直在尝试找到在哪里添加它,但我似乎找不到它
  • 参见stackoverflow.com/a/14153027/586873 设置包含路径。您可能还需要将自定义库路径指定为-L/usr/local/lib,并告诉-lgmp 使用它。有关整个过程,另请参阅stackoverflow.com/questions/13955996/linking-gmp-to-xcode-4-5(实际上我认为这只是您的问题的重复)。
  • 太棒了,我看看谢谢!
  • 你想知道 GMP 中的 lib 文件是否被称为 libgmp.la 和 libgmpxx.la,如果这些是我需要包含的唯一文件

标签: c++ c xcode gmp


【解决方案1】:
this is the fix according to another SO question:

1) Open the left panel, 
   goto "ProjectName", Targets, Build phases, Link binary with libraries 
   and select your library.

2) Open the left panel,
   goto "ProjectName", Project, Header Search Paths, 
   write the path where the headers of your library are 
   (the .h files, usually in /usr/local/include).

3) Open the left panel, 
   goto "ProjectName", Project, Library Search Paths, 
   write the path where your libraries are 
   (the .a or .dylib files, usually in /usr/local/lib)

【讨论】:

  • 一个很好的人给我看了这个链接,我试过了,但它似乎没有用。难的是Xcode从那以后发生了变化,但遗憾的是我没有骰子。我真的很感谢你花时间发布这个。我会继续努力……
  • 你为什么要把你的整个答案放在一个代码块中?引用某些内容时,最好提供链接。
猜你喜欢
  • 2014-05-13
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多