0

I am trying to compile a simple C program using GCC with MPIR under MinGW on my Windows 7 machine. I installed MPIR successfully (I guess) with configure, make, make check and make install (did not use "sudo" - what is this?).

The program is called "mytest.cpp", sits in the top folder of MPIR, namely C:/MPIR/mpir-2.7.0/, where also "mpir.h" is sitting (is it "the" (correct one? are there several?) mpir.h?):

#include "mpir.h"
using namespace std;

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

I tried compiling via

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

with the hope that GCC would then be able to locate mpir.h, "-lmpir" because a helpful developer told me to; but then it says:

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

where "[...]" stands for some directory up-and-down-climbs inside the "minGW" directory. However, I am with the shell currently in the C:/MPIR/mpir-2.7.0/ directory.

What is wrong? How to make GCC find the mpir files? Should the compile option "-I" be spelled differently? I also heard about some "-L" option but could not find that anywhere. Thanks.

4

2 回答 2

1

改变

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 标志链接到的库。

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

于 2015-06-03T16:29:11.617 回答
0

好的,我修好了。
总而言之,关键点是:
- 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

最好的。

于 2015-06-03T23:20:32.100 回答