MPIR gcc 编译 - 找不到 -lmpir

MPIR gcc compilation - cannot find -lmpir

我正在尝试在我的 Windows 7 机器上使用 GCC 和 MPIR 在 MinGW 下编译一个简单的 C 程序。我通过 configure、make、make check 和 make install 成功安装了 MPIR(我猜)(没有使用 "sudo" - 这是什么?)。

程序名为"mytest.cpp",位于MPIR的顶层文件夹,即C:/MPIR/mpir-2.7.0/,"mpir.h"也位于其中(是"the"(正确的一个?有几个吗?)mpir.h?):

#include "mpir.h"
using namespace std;

int main ()
{
  mpz_t z; 
  mpz_init(z);   
  return 0;
}

我尝试通过

编译

gcc mytest.c -o mytest -lmpir -I/C:/MPIR/mpir-2.7.0/

希望 GCC 能够找到 mpir.h、“-lmpir”,因为一位乐于助人的开发人员告诉我这样做;但随后它说:

"C:/mingw/ [...] /bin/ld.exe: cannot find -lmpir"

其中“[...]”代表 "minGW" 目录中的某些目录上下爬升。但是,我目前在 shell C:/MPIR/mpir-2.7.0/目录.

怎么了?如何让 GCC 找到 mpir 文件?编译选项“-I”是否应该拼写不同?我还听说过一些“-L”选项,但在任何地方都找不到。谢谢

改变

gcc mytest.c -o mytest -lmpir -I/C:/MPIR/mpir-2.7.0/

gcc mytest.c -o mytest -lmpir -IC:/MPIR/mpir-2.7.0/ -LC:/MPIR/mpir-2.7.0

您不需要在 C: 前面使用 / 并且 -L 标志告诉链接器在哪里可以找到您使用 -l 标志链接到的库。

此外,我建议您使用相对路径而不是绝对路径指向您的包含和库。

好的,我修好了。
总结一下,关键点是:
- gcc 选项的顺序很重要:“-o mytest”需要走到最后,“-lname”在“-Ldir”之前和之后;
- 路径末尾应该有“.libs”,因为这是库所在的位置(即使它们不需要命名 libmpir.a)
-(至少在 MinGW 中)工作格式是 c:/MPIR/mpir-2.7.0/.libs(因此是绝对的,也来自 /usr/local/ 或其他地方)

有效的例子是:

$ gcc mytest.c -Lc:/MPIR/mpir-2.7.0/.libs -lmpir -o mytest
$ gcc mytest.c -Lc:/MPIR/mpir-2.7.0/.libs -lmpir.dll -o mytest

最佳。