我正在尝试在 CodeBlocks 中使用 GCC 4.7.1 打印一个四倍精度向量。这是代码:
#include <iostream>
#include <vector>
#include <quadmath.h>
...
int width = 46;
char buf[128];
for (std::vector<__float128>::const_iterator i = sol_r.begin(); i != sol_r.end(); ++i)
{
int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, *i);
if ((size_t) n < sizeof buf)
{
std::cout << buf << ' ';
}
}
我得到这个错误:undefined reference to 'quadmath_snprintf(char*, unsigned int, char const*, ...)'
。我究竟做错了什么?
关于重复声明,表示为重复的答案确实包含解决方案的一部分,但这是一个包括几个不同问题的一般问题。
在打印四倍精度向量时遇到问题的用户很可能是没有经验的(就像我一样),并且会从更简洁的答案和/或更精确的来源中受益更多。
这里提出的问题可以通过检查来解决:
https://gcc.gnu.org/ml/gcc-help/2011-06/msg00148.html(将标题添加为外部)
什么是未定义的引用/未解决的外部符号错误,我该如何解决?(将相关库链接为libquadmath
)