MinGW链接器找不到MPICH2库 [英] MinGW linker can't find MPICH2 libraries

查看:200
本文介绍了MinGW链接器找不到MPICH2库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MPICH2安装在C:\ Program Files \MPICH2中。有两个子目录(感兴趣的), \include ,其中包含.h文件, \lib 包含.bib文件。

MPICH2附带的自述文件包含以下指令:


  1. create a makefile

  2. 添加 -I ... mpich2 \include

  3. 添加 -L ... mpich2 \lib

  4. 添加 -lmpi

  5. 为您的源文件添加规则

  6. 编译



  7. 由于在我的项目中没有其他规则,所以我没有创建makefile,只是转到命令行并尝试编译,如下所示:

    g ++ -IC:\ Program Files \MPICH2\includemain.cpp -LC:\ Program Files \MPICH2\lib-lmpi

    这给我一个未定义参考代码中的MPI符号。我花了好几个小时试图解决它,玩弄 -I -L -l 切换,混洗参数的顺序,甚至将所有.lib文件复制到与我的源相同的目录中,但似乎没有任何效果。



    要得到这个东西需要什么样的voodoo链接?






    编辑:我想我发现了这个问题:下面是详细模式下链接器输出的摘录(向编译命令添加 -Wl, - verbose ):

     尝试打开C:\程序文件\ MPICH2 \ lib / libmingwex.dll.a失败
    尝试打开C:\程序文件\ MPICH2 \\ \\ lib / mingwex.dll.a失败
    尝试打开C:\程序文件\ MPICH2 \ lib / libmingwex.a失败
    尝试打开C:\程序文件\ MPICH2 \\ \\ lib / mingwex.lib失败
    尝试打开C:\程序文件\ MPICH2 \ lib / libmingwex.dll失败
    尝试打开C:\程序文件s \ MPICH2 \ lib / mingwex.dll失败
    尝试打开C:\ Program Files \MPICH2\lib\libmingwex.a失败

    显然,链接器添加了一个 / 而不是 \ 添加到我提供的目录名称中(除了在某些原因下查找 lib ___。a 格式时),这显然不是有效的路径。有没有什么方法可以告诉链接器使用反斜杠而不是斜杠?



    这也引起了我的注意:

     尝试打开/mingw/lib/libmingwex.a成功

    所以我试着像这样编译:

      g ++ -I/ Program Files / MPICH2 / include-L/ Program Files / MPICH2 / libobjManager.cpp ongom.cpp io.cpp main.cpp -lmpi -lcxx 

    但我仍然得到相同的未定义的引用错误。

    解决方案

    strong>能够找到您的图书馆。否则,它会报告:找不到-lmpi



    不知何故,例程无法找到在该库中。我设法用这个语法编译了一个例子:

      g ++ -I ../ include cpilog.c ../lib/mpi .lib ../lib/mpe.lib 

    我在msys里面做了这个。



    删除 libmpi.a 文件后,它也可以工作:

      g ++ -I ../ include -L ../ lib cpilog.c -lmpi -lmpe 


    MPICH2 is installed in C:\Program Files\MPICH2. There are two subdirectories (of interest), \include which contains .h files, and \lib which contains .lib files.

    The readme that comes with MPICH2 has the following instructions:

    1. create a makefile
    2. add –I...mpich2\include
    3. add –L...mpich2\lib
    4. add –lmpi
    5. add the rules for your source files
    6. compile

    Since there are no other rules in my project, I don't create a makefile, I just go to the command line and try compiling like this:

    g++ -I"C:\Program Files\MPICH2\include" main.cpp -L"C:\Program Files\MPICH2\lib" -lmpi
    

    This gives me a fistful of undefined reference errors on every single MPI symbol in the code. I spent hours trying to fix it, juggling -I, -L and -l switches around, shuffling the order of the parameters, even copied all the .lib files into the same directory as my source, but nothing seems to work.

    What kind of voodoo is needed to get this thing to link?


    EDIT: I think I found the problem: here's an excerpt of the linker's output in verbose mode (adding -Wl,--verbose to the compile command):

    attempt to open C:\Program Files\MPICH2\lib/libmingwex.dll.a failed
    attempt to open C:\Program Files\MPICH2\lib/mingwex.dll.a failed
    attempt to open C:\Program Files\MPICH2\lib/libmingwex.a failed
    attempt to open C:\Program Files\MPICH2\lib/mingwex.lib failed
    attempt to open C:\Program Files\MPICH2\lib/libmingwex.dll failed
    attempt to open C:\Program Files\MPICH2\lib/mingwex.dll failed
    attempt to open C:\Program Files\MPICH2\lib\libmingwex.a failed
    

    Apparently, the linker adds a / instead of a \ to the directory names I supply it with (except when looking for the lib___.a format for some reason), which is obviously not a valid path. Is there any way to tell the linker to use backslashes instead of slashes?

    This also caught my eye:

    attempt to open /mingw/lib/libmingwex.a succeeded
    

    So I tried compiling like this:

    g++ -I"/Program Files/MPICH2/include" -L"/Program Files/MPICH2/lib" objManager.cpp ongom.cpp io.cpp main.cpp -lmpi -lcxx
    

    But I still get the same undefined reference errors.

    解决方案

    GCC is able to find your library. Otherwise it would report: cannot find -lmpi.

    Somehow it happens that the routines cannot be found in that library. I managed to compile an example with this syntax:

    g++ -I../include cpilog.c ../lib/mpi.lib ../lib/mpe.lib
    

    I did that inside msys though. And my directory does not contain spaces.

    After removing libmpi.a file, this also works:

    g++ -I../include -L../lib cpilog.c -lmpi -lmpe
    

    这篇关于MinGW链接器找不到MPICH2库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆