gpt4 book ai didi

c++ - 使用 FLTK 时出现 cmath 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:26:03 24 4
gpt4 key购买 nike

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

main.cpp

#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)

谁能告诉我这是怎么回事?谢谢!

最佳答案

纯属猜测,但是 /usr/include/FL 中是否有“math.h” header ?在任何情况下?或者那里是否有其他标题包含在 cmath 中? ?

[...一点点时间过去了...]

仍然是推测,但考虑到评论“是的,有 - 发生了什么事?”,我推测/usr/include 中没有“math.h” header - 因为如果有 GCC (G++)通常从与 '' 相同的地方取货。因此,我会检查已安装的软件 -/usr/include 下的 header - 是否正常。

[...又过了一点时间...]

啊,嗯……看来问题是有两个math.h header ,编译器选择了错误的 header 。

您可以尝试一些技巧。首先,也许是检查 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 .这绝对不如第一个选项可靠。

关于c++ - 使用 FLTK 时出现 cmath 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1436326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com