使用 FLTK 时出现 cmath 错误
由于某种原因,每当我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
纯属猜测,但
/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
下找到
一样)。如果这不是答案的一部分,那么您可以尝试使用标志:
这表示“在搜索
/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 bycmath
?[...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:
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.我有类似的问题。这是由于 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 themath.h
file. The I found it was to simply do afind / -name math.h
. Sure it may take a while, but it gets them all.Scott,将
-lm
添加到链接器标志列表中,就可以了。Scott, add
-lm
to the list of linker flags there, and you'll be fine.我使用 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!!!