4

出于某种原因,每当我将 FLTK 目录添加到我的包含路径时,我都会从cmath收到一堆错误。我正在使用 GCC 4.2 版。这是一个示例程序和构建输出:

主文件

#include <cmath>

int main()
{
    return 0;
}

**** Build of configuration Debug for project CMath Test ****

make -k all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/FL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
In file included from ../main.cpp:1:
/usr/include/c++/4.2/cmath:100: error: ‘::acos’ has not been declared
/usr/include/c++/4.2/cmath:116: error: ‘::asin’ has not been declared
/usr/include/c++/4.2/cmath:132: error: ‘::atan’ has not been declared
/usr/include/c++/4.2/cmath:148: error: ‘::atan2’ has not been declared
/usr/include/c++/4.2/cmath:165: error: ‘::ceil’ has not been declared
/usr/include/c++/4.2/cmath:181: error: ‘::cos’ has not been declared
/usr/include/c++/4.2/cmath:197: error: ‘::cosh’ has not been declared
/usr/include/c++/4.2/cmath:213: error: ‘::exp’ has not been declared
/usr/include/c++/4.2/cmath:229: error: ‘::fabs’ has not been declared
/usr/include/c++/4.2/cmath:245: error: ‘::floor’ has not been declared
/usr/include/c++/4.2/cmath:261: error: ‘::fmod’ has not been declared
/usr/include/c++/4.2/cmath:271: error: ‘::frexp’ has not been declared
/usr/include/c++/4.2/cmath:287: error: ‘::ldexp’ has not been declared
/usr/include/c++/4.2/cmath:303: error: ‘::log’ has not been declared
/usr/include/c++/4.2/cmath:319: error: ‘::log10’ has not been declared
/usr/include/c++/4.2/cmath:335: error: ‘::modf’ has not been declared
/usr/include/c++/4.2/cmath:354: error: ‘::pow’ has not been declared
/usr/include/c++/4.2/cmath:376: error: ‘::sin’ has not been declared
/usr/include/c++/4.2/cmath:392: error: ‘::sinh’ has not been declared
/usr/include/c++/4.2/cmath:408: error: ‘::sqrt’ has not been declared
/usr/include/c++/4.2/cmath:424: error: ‘::tan’ has not been declared
/usr/include/c++/4.2/cmath:440: error: ‘::tanh’ has not been declared
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project CMath Test

g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

谁能告诉我怎么了?谢谢!

4

4 回答 4

4

纯粹的猜测,但是否有一个“math.h”标题/usr/include/FL?或者那里是否有其他一些标题包含在cmath

[……过了一会儿……]

仍在猜测,但鉴于评论“是的,有 - 发生了什么?”,我会推测 /usr/include 中没有“math.h”标头 - 因为如果有 GCC(G++)通常会拿起来自与''相同的地方。所以,我会检查已安装的软件 - /usr/include 下的头文件 - 是否健全。

[……还有一点时间过去了……]

啊,好吧...似乎问题在于有两个math.h标头,而编译器选择了错误的标头。

您可以尝试一些技巧。首先,也许是检查 FLTK 的文档:您应该使用<FL/header.h>还是只是<header.h>访问它的标头?如果你应该使用带有子目录的版本,那么你不需要添加-I/usr/include/FL到编译命令行;对的引用<FL/header.h>将被自动处理(通过/usr/include/FL/header.h在扫描时查找/usr/include- 就像<sys/types.h>在 下找到的一样/usr/include)。

如果这不是答案的一部分,那么您可以尝试使用标志:

-I/usr/include -I/usr/include/FL

这表示“在搜索/usr/include之前搜索/usr/include/FL(然后在搜索之后/usr/include再次搜索/usr/include/FL)”。这应该可以解决眼前的问题 - 但是它可能会导致任何应该包含的问题/usr/include/FL/math.h。这绝对不如第一种选择可靠。

于 2009-09-17T03:07:44.657 回答
4

我有一个类似的问题。这是由于math.hQt Creator 无意中在包含路径中创建了 a ,为我创建了隐藏math.h文件的项目的数学子包。我发现它只是简单地做一个find / -name math.h. 当然这可能需要一段时间,但它会得到所有的。

于 2012-11-18T19:07:15.020 回答
0

斯科特,添加-lm到那里的链接器标志列表中,你会没事的。

于 2011-11-02T09:33:42.887 回答
0

我使用 Qt Creator 3.3.0 并遇到了同样的问题

有趣的是我通过移动线路解决了它

#include <cmath>

在其他 #includes 之前到顶行

解决了我的问题!!!

于 2015-02-09T11:59:58.380 回答