でコンパイルしたとき、私は、私はg ++の使用時にエラーがない、LinuxのUbuntuので簡単なプログラムを書いたが、私はgccのを使用するとき、私はこのエラーを参照してください。「cmath:そのようなファイルやディレクトリはありませんが、」GCC
をtest.c:1:17: fatal error: cmath: No such file or directory #include <cmath>
注:実際には、このエラーがパッケージをコンパイルするのを見ると、linux環境に設定されていないgccライブラリに関係している可能性があるので、エラーを明確に判断する簡単なプログラムを書きました。ウィットアウト依存! プログラムはgccでコンパイルする必要があります。 私はcmathの代わりにmath.hを使うことができますが、packegeはcmathを使いました! これは単純なプログラムです。ここ
/*test.c*/
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(){
double sinx = sin(3.14/3);
cout<< "sinx= " << sinx;
return 0;
}
がcmath pathesです:
roo[email protected]:/# find -name cmath
./opt/root5.32.00/cint/cint/include/cmath
./app/gcc/4.8.0/include/c++/4.8.0/ext/cmath
./app/gcc/4.8.0/include/c++/4.8.0/cmath
./app/gcc/4.8.0/include/c++/4.8.0/tr1/cmath
./usr/include/boost/compatibility/cpp_c_headers/cmath
./usr/include/boost/tr1/tr1/cmath
./usr/include/c++/4.5/cmath
./usr/include/c++/4.5/tr1_impl/cmath
./usr/include/c++/4.5/tr1/cmath
./usr/include/c++/4.6/cmath
./usr/include/c++/4.6/tr1/cmath
./usr/share/gccxml-0.9/GCC/2.95/cmath
./gcc-build/gcc-4.8.0/stage1-i686-pc-linux-gnu/libstdc++-v3/include/ext/cmath
./gcc-build/gcc-4.8.0/stage1-i686-pc-linux-gnu/libstdc++-v3/include/cmath
./gcc-build/gcc-4.8.0/stage1-i686-pc-linux-gnu/libstdc++-v3/include/tr1/cmath
./gcc-build/gcc-4.8.0/i686-pc-linux-gnu/libstdc++-v3/include/ext/cmath
./gcc-build/gcc-4.8.0/i686-pc-linux-gnu/libstdc++-v3/include/cmath
./gcc-build/gcc-4.8.0/i686-pc-linux-gnu/libstdc++-v3/include/tr1/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/include/ext/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/include/c/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/include/c_global/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/include/c_std/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/include/tr1/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/testsuite/26_numerics/headers/cmath
./gcc-build/gcc-4.8.0/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath
./gcc-build/gcc-4.8.0/prev-i686-pc-linux-gnu/libstdc++-v3/include/ext/cmath
./gcc-build/gcc-4.8.0/prev-i686-pc-linux-gnu/libstdc++-v3/include/cmath
./gcc-build/gcc-4.8.0/prev-i686-pc-linux-gnu/libstdc++-v3/include/tr1/cmath
とgcc-4.8をインストールした後、私はこの命令をした:
[email protected]:~/Desktop# update-alternatives --install /usr/bin/gcc gcc /app/gcc/4.8.0/bin/gcc 40 --slave /usr/bin/g++ g++ /app/gcc/4.8.0/bin/g++
[email protected]:~/Desktop#update-alternatives --install /usr/bin/gcc gcc /app/gcc/4.8.0/bin/gcc 60 --slave /usr/bin/g++ g++ /app/gcc/4.8.0/bin/g++
[email protected]:~/Desktop# update-alternatives --config gcc
のgcc-4.8の私を作るためにデフォルトのgcc。今
[email protected]:~/Desktop# gcc --version
gcc (GCC) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
実際の問題として、私は私が何をすべきか知っている `tを私
助けてくださいhttps://askubuntu.com/questions/309195/cmath-no-such-file-or-directory-include-cmath
で主な問題を書きました。
ありがとう
+1よくある質問とエラーをはっきりと判断するためのコードを簡略化します。 – Abhineet
cmathはC++用ですが、Cでmath.hを使用してください。ファイルが.cで終わっていても、明らかにC++ファイルであれば、エンディングを変更してください。 – stdcall