使用 FLTK 时出现 cmath 错误

发布于 2024-08-04 19:15:54 字数 2809 浏览 12 评论 0原文

由于某种原因,每当我将 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)

谁能告诉我出了什么问题?谢谢!

For some reason, whenever I add the FLTK directory to my include path, I get a bunch of errors from cmath. I am using GCC version 4.2. Here is a sample program and the build output:

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)

Can anyone tell me what's wrong? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌若浮生 2024-08-11 19:15:54

纯属猜测,但 /usr/include/FL 中是否有“math.h”标头?或者 cmath 中是否包含其他标头?

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

仍然是猜测,但考虑到评论“是的,有 - 发生了什么事?”,我会推测不存在 'math.h' /usr/include 中的标头 - 因为如果有 GCC (G++) 通常会从与 '' 相同的位置获取。因此,我会检查已安装的软件 - /usr/include 下的标头 - 是否健全。

[...再过一段时间...]

啊,好吧...问题似乎是有两个 math.h 标头,并且编译器选择了错误的一个。

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

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

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

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

Pure speculation, but is there a 'math.h' header in /usr/include/FL by any chance? Or is there some other header in there that is included by cmath?

[...a little time passes...]

Still speculation, but given the comment "Yes, there is - what's going on?", I will speculate that there is no 'math.h' header in /usr/include - because if there was GCC (G++) would normally pick up from the same place as ''. So, I would check the installed software - headers under /usr/include - for sanity.

[...a little more time passes...]

Ah, well...it seems that the problem is that there are two math.h headers, and the compiler is picking the wrong one.

There are a couple of tricks you can try. First, perhaps, is to check the documentation of FLTK: are you supposed to use <FL/header.h> or just <header.h> to access its headers? If you are supposed to use the version with the sub-directory, then you don't need to add -I/usr/include/FL to the compilation command line; the references to <FL/header.h> will be handled automatically (by looking for /usr/include/FL/header.h when scanning /usr/include - just like <sys/types.h> is found under /usr/include).

If that isn't part of the answer, then you can try using the flags:

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

This says "search /usr/include before searching /usr/include/FL (and then search /usr/include again after searching /usr/include/FL)". That should solve the immediate problem - however it might cause trouble with whatever is supposed to include /usr/include/FL/math.h. This is definitely not as reliable as the first option.

风苍溪 2024-08-11 19:15:54

我有类似的问题。这是由于 Qt Creator 在包含路径中无意中创建了一个 Math.h 造成的,Qt Creator 为我创建了一个隐藏了 math.h 文件的数学子包。我发现只需执行 find / -name math.h 即可。当然,这可能需要一段时间,但它可以解决所有问题。

I had a similar problem. It was caused by an inadvertent creation of a math.h in the include path by Qt Creator creating a math subpackage for me the project that hid the math.h file. The I found it was to simply do a find / -name math.h. Sure it may take a while, but it gets them all.

九八野马 2024-08-11 19:15:54

Scott,将 -lm 添加到链接器标志列表中,就可以了。

Scott, add -lm to the list of linker flags there, and you'll be fine.

忆梦 2024-08-11 19:15:54

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

有趣的是,我通过移动行

#include <; 解决了这个问题。 cmath>

在其他 #includes 之前到顶行

它解决了我的问题!

I use Qt Creator 3.3.0 and got the same problem

It's funny that I have solved it by moving the line

#include < cmath>

to the top line before other #includes

It solves my problems!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文