4

何らかの理由で、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)

誰が何が悪いのか教えてもらえますか? ありがとう!

4

4 に答える 4

4

純粋な推測ですが、「math.h」ヘッダーが含ま/usr/include/FLれている可能性はありますか? または、そこに含まれている他のヘッダーがありcmathますか?

[...少し時間が経ちます...]

まだ憶測ですが、「はい、あります-何が起こっているのですか?」というコメントを考えると、/usr/include に「math.h」ヘッダーがないと推測します-GCC (G++) があれば通常はピックアップするためです。 「」と同じ場所から。そのため、インストールされているソフトウェア (/usr/include の下のヘッダー) の健全性をチェックします。

[...もう少し時間が経ちます...]

ああ、まあ...問題は 2 つの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。これは間違いなく、最初のオプションほど信頼性が高くありません。

于 2009-09-17T03:07:44.657 に答える
4

同様の問題がありました。これは、ファイルmath.hを非表示にするプロジェクトの数学サブパッケージを作成する Qt Creator によって、インクルード パスに が不注意に作成されたことが原因でした。math.h私が見つけたのは、単にfind / -name math.h. 確かに時間がかかるかもしれませんが、すべて取得できます。

于 2012-11-18T19:07:15.020 に答える
0

スコット、-lmリンカー フラグのリストに追加してください。

于 2011-11-02T09:33:42.887 に答える