FLTK使用時のcmathエラー
-
07-07-2019 - |
質問
何らかの理由で、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'ヘッダーがありますか?または、cmath
?
[...少し時間が経った...]
まだ推測ですが、コメント<!> quot;はい、あります-何が起こっていますか?<!> quot;、/ usr / includeに 'math.h'ヘッダーがないと推測します- GCC(G ++)がある場合、通常は ''と同じ場所から取得します。したがって、インストールされているソフトウェア(/ usr / includeの下のヘッダー)が健全であることを確認します。
[...もう少し時間がかかります...]
あ、まあ...問題は2つのmath.h
ヘッダーがあり、コンパイラが間違ったヘッダーを選択していることだと思われます。
試すことができるいくつかのトリックがあります。まず、おそらく、FLTKのドキュメントを確認することです。そのヘッダーにアクセスするために<FL/header.h>
または単に<header.h>
を使用することになっていますか?サブディレクトリでバージョンを使用することになっている場合は、コンパイルコマンドラインに-I/usr/include/FL
を追加する必要はありません。 /usr/include/FL/header.h
への参照は自動的に処理されます(/usr/include
をスキャンするときに<sys/types.h>
を探すことにより、/usr/include/FL/math.h
に<=>が見つかるように)
それが答えの一部ではない場合、フラグを使用してみてください:
-I/usr/include -I/usr/include/FL
これは、<=>を検索する前に<!> quot; search <=>を意味します(そして<=>を検索した後に<=>を再度検索します)<!> quot;。これは差し迫った問題を解決するはずです-ただし、<=>を含むことになっているものすべてに問題を引き起こす可能性があります。これは間違いなく最初のオプションほど信頼性がありません。
他のヒント
同様の問題がありました。これは、Qt Creatorがmath.h
ファイルを非表示にしたプロジェクト用の数学サブパッケージを作成して、インクルードパスにfind / -name math.h
を誤って作成したために発生しました。私はそれが単に<=>をすることであるとわかりました。確かにそれはしばらくかかるかもしれませんが、すべてを取得します。
スコット、リンカーフラグのリストに-lm
を追加すれば大丈夫です。
Qt Creator 3.3.0を使用していますが、同じ問題が発生しました
行を移動して解決したのは面白いです
#include <!> lt; cmath <!> gt;
他の#includesの前の最上行に
それは私の問題を解決します!!!