出于某种原因,每当我将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)
谁能告诉我什么是错的?谢谢!
答案 0 :(得分:4)
纯粹的推测,但/usr/include/FL
中是否有'math.h'标题?或者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
的问题。这绝对不如第一个选项那么可靠。
答案 1 :(得分:4)
我有类似的问题。这是由于Qt Creator在包含路径中无意中创建了math.h
而导致我为隐藏math.h
文件的项目创建了一个数学子包。我发现这只是做find / -name math.h
。当然可能需要一段时间,但它可以解决所有问题。
答案 2 :(得分:0)
Scott,将-lm
添加到那里的链接器标记列表中,你会没事的。
答案 3 :(得分:0)
我使用Qt Creator 3.3.0并遇到了同样的问题
有趣的是我通过移动线解决了它
#include&lt; cmath&gt;
到其他#include
之前的第一行它解决了我的问题!!!