简体   繁体   English

c ++并链接到lapack

[英]c++ and link to lapack

I have several files which I need to compile together as following in my makefile (names are dummy now): 我有几个文件,我需要在我的makefile中编译如下(名称现在为虚拟):

compile:
        g++ prog1.cpp func1.cpp func2.cpp func3.cpp -L/usr/lib/ -lmkl_lapack64 -lmkl 
        -lguide -lpthread -o output_ready.out

When I do make compile, then I get the following errors: 当我编译时,我得到以下错误:

/usr/bin/ld: cannot find -lmkl_lapack64                                                                                                                                                
/usr/bin/ld: cannot find -lmkl                                                                                                                                                         
/usr/bin/ld: cannot find -lguide                                                                                                                                                       
collect2: ld returned 1 exit status                                                                                                                                                    
make: *** [compile] Error 1 

This program was correctly compiled in another machine previously. 以前在另一台机器上正确编译了该程序。

Q: How can I check the path for lapack lib if they are correct? 问:如果正确,我如何检查lapack lib的路径? How should I fix them? 我应该怎么解决它们? The libraries are installed (not sure if with the right path). 安装库(不确定是否使用正确的路径)。

Any helpful comment is highly appreciated. 任何有用的评论都非常感谢。 R [R

The only path where he looks for the lapack libs is /usr/lib - since that's the only dircetory you specified for the linker. 他寻找lapack libs的唯一途径是/usr/lib - 因为这是你为链接器指定的唯一的dircetory。 If the libs are installed in another location you will have to find it out and 如果libs安装在另一个位置,你将不得不找到它

  • provide that location to the linker via another -L parameter, 通过另一个-L参数向链接器提供该位置,
  • or move the libs to /usr/lib 或者将libs移动到/usr/lib

so the linker can find the libs. 所以链接器可以找到libs。

I don't think you need -L/usr/lib as I believe the compiler already knows to look there for libraries. 我认为你不需要-L/usr/lib因为我相信编译器已经知道在那里寻找库。 That said, you do need -L<path to where lapack libraries are> if they were not installed in a standard location. 也就是说,如果没有安装在标准位置,你需要-L<path to where lapack libraries are>

First of all I would have suggested you to check if libraries are installed in correct directories, as you planned yourself. 首先,我建议你检查库是否安装在正确的目录中,正如你自己计划的那样。 An obvious way to do this is just to cd /usr/lib and see whether there are any lapack libraries (you will notice them at once). 一个显而易见的方法就是cd /usr/lib并查看是否有任何lapack库(你会立刻注意到它们)。

If everything is installed where it should have been, I would suggest you to compile with 如果一切都安装在应有的地方,我建议你编译

-I /usr/local/include/lapackpp/ 

for headers, and 对于标题,和

-L /usr/local/lib -llapackpp 

for libraries, as all lapack libraries should be accessed through it. 对于库,因为所有的lapack库都应该通过它来访问。

Also, are you sure you want to look for libraries in /usr/lib , but not in /usr/local/lib ? 另外,您确定要在/usr/lib查找库,而不是在/usr/local/lib查找库吗? I guess this is OS/settings specific, though. 我想这是特定于操作系统/设置的。

Finally, some time ago I have had similar problem to the one you have and found a good and explicit explanation on this website. 最后,前段时间我遇到了类似的问题,并在本网站上找到了明确的解释。 :-) :-)

An excellent way to find the correct compiler and linker flags based on your OS, architecture, etc. is using the Intel online tool, which you can find here: 根据您的操作系统,体系结构等找到正确的编译器和链接器标志的绝佳方法是使用英特尔在线工具,您可以在此处找到:

https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor . https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor

To access it, you need to login to the Intel website. 要访问它,您需要登录英特尔网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM