使用 PGI 编译器链接到犰狳库的 Makefile

Posted

技术标签:

【中文标题】使用 PGI 编译器链接到犰狳库的 Makefile【英文标题】:Makefile to link against Armadillo library using the PGI compiler 【发布时间】:2015-11-03 22:24:04 【问题描述】:

我正在尝试在 Makefile 中使用 PGI 编译器的 -U__GNUG__ 标志,尝试编译文件夹中的所有 .cpp 文件,链接 Armadillo(使用 g++ 编译器,代码编译并运行。)Makefile我有如下:

CC=pgc++ 
CFLAGS= -U__GNUG__  -std=c++11 -fast -acc  -Minfo=accel -larmadillo -lgsl -w 

all: 
   $CC $CFLAGS *.cpp -o cg 
clean: 
   rm -Rf cg pgprof* *.o core

似乎可以编译对象文件,但无法编译最终的可执行文件。这个 Makefile 有什么问题?

编译代码使用:

~$ make

我收到以下错误:

cis.o: In function `arma::Col<double>::pod_type arma::op_norm::vec_norm_2<arma::Col<double> >(arma::Proxy<arma::Col<double> > const&, arma::arma_not_cx<arma::Col<double>::elem_type>::result const*)':
/usr/local/include/armadillo_bits/debug.hpp:173: undefined reference to `isfinite'
cis.o: In function `double arma::op_norm::vec_norm_2_direct_std<double>(arma::Mat<double> const&)':
/usr/local/include/armadillo_bits/debug.hpp:173: undefined reference to `isfinite'
cis.o: In function `void arma::arma_ostream::print_elem<double>(std::ostream&, double const&, bool)':
/usr/local/include/armadillo_bits/debug.hpp:173: undefined reference to `isfinite'
cis.o: In function `std::isfinite(double)':
/usr/local/include/armadillo_bits/debug.hpp:173: undefined reference to `isfinite'
cis.o: In function `bool arma::arma_isfinite<double>(double)':
/usr/local/include/armadillo_bits/debug.hpp:173: undefined reference to `isfinite'
davidson.o:davidson.cpp:(.gnu.linkonce.t._ZN4arma7op_norm10vec_norm_2INS_11subview_colIdEEEENT_8pod_typeERKNS_5ProxyIS4_EEPKNS_11arma_not_cxINS4_9elem_typeEE6resultE+0x2bb): more undefined references to `isfinite' follow
pgacclnk: child process exit status 1: /usr/bin/ld
make: *** [all] Error 2

这应该通过包含标志 -U__GNUG__ 来解决。

任何建议将不胜感激。

【问题讨论】:

make 是否使用您希望它用来编译二进制文件的命令? (您没有在粘贴的输出中包含它。) 【参考方案1】:

这似乎是 PGI pgc++ 编译器的一个问题,其中“std::isfinite”在存在 C++11 的情况下没有被正确处理。删除“--c++11”标志将解决该问题。

我添加了一个问题报告,PGI TPR#22065,我们希望在未来的版本中解决这个问题。

【讨论】:

感谢您的回答,但问题更多,因为相同的代码在使用 pgc++ 编译之后执行时会产生错误的结果。有什么想法吗? 不是随便的,虽然我猜这两个问题是不相关的。您可以为错误答案发布一个小的复制示例吗?

以上是关于使用 PGI 编译器链接到犰狳库的 Makefile的主要内容,如果未能解决你的问题,请参考以下文章

将犰狳 lapack blas 链接到代码时出错:未定义对“dtrsm_”的引用

CentOS 7上安装PGI 2017编译器

了解 Makefile。 make 无法链接犰狳库

在 Xcode 4 中链接和编译犰狳

犰狳初始化列表不起作用

链接 Yaml-cpp 和 Armadillo 共享库的 CMake 项目