• 締切済み

C++コンパイルエラーの原因を教えてください

Cには詳しいのですが、C++があまりよくわかっておらず、質問させてください。 今回、手に入れたC++のあるプログラムをmakeしています(x86_64 Linux)。 以下のようなエラーが出てコンパイルできないのですが、何が悪いのか全く理解できず困っています。 他の環境ではコンパイルできているらしいので、わたしの環境の何が悪いのか、考えられることがありましたら、何でも書き込んでいただけると嬉しいです。 よろしくお願いします。 g++ -c -I../MathUtils -I../CommonUtils -DHAVE_ZLIB -DHAVE_BZLIB -fomit-frame-pointer -O2 -DFTYPE=float -Wall -Wsign-compare -Wpointer-arith -pedantic -DHAVE_PGPLOT -I. -DHAVE_FFTW -o analyse_image.o analyse_image.cpp In file included from analyse_image.cpp:21: Tools.h:16:15: warning: anonymous variadic macros were introduced in C99 analyse_image.cpp: In function ‘int main(int, char**)’: analyse_image.cpp:114: error: ‘strcmp’ was not declared in this scope analyse_image.cpp:205: error: ‘exit’ was not declared in this scope analyse_image.cpp:209: error: ‘strstr’ was not declared in this scope analyse_image.cpp:216: error: ‘exit’ was not declared in this scope analyse_image.cpp:457: error: ‘strlen’ was not declared in this scope make: *** [analyse_image.o] Error 1

  • JF1Msf
  • お礼率56% (201/354)

みんなの回答

  • jacta
  • ベストアンサー率26% (845/3158)
回答No.1

ソースがないので断定できませんが、おそらくはヘッダのインクルード忘れかと思います。

JF1Msf
質問者

お礼

さっそくのご回答、ありがとうございました。 いろいろと調べたところ、うまくコンパイルできる他機ではgccのバージョンが3.4であることがわかりました。 そこで、4.3から3.4にバージョンを下げたいのですが、どうすれば良いのでしょうか? 質問を仕切り直すことにします。

関連するQ&A

  • wxGladeで生成したhello.cpp&hello.hファイルをコンパイルしようとするとエラーが出ます

    http://0xcc.net/pub/uu-2004-08/ や http://d.hatena.ne.jp/foral/20061224 を見て、wxGladeで生成したhello.cpp&hello.hファイルをMSYSのコンソールから g++ -c hello.cpp 'wx-config --cxxflags --libs' でコンパイルしようとしたのですが、以下のようなエラーが出てコンパイルできません。 環境はWindows XP MinGW&MSYS wxWidgets2.8.7 (パスは、C:\msys\1.0\home\owner) です。 普通のC++ファイルのコンパイルは出きるのですがwxWidetsが絡むとできないようです。 In file included from hello.cpp:3: hello.h:3:10: #include expects "FILENAME" or <FILENAME> hello.h:4:10: #include expects "FILENAME" or <FILENAME> In file included from hello.cpp:3: hello.h:13: error: expected class-name before '{' token hello.h:18: error: expected `)' before '*' token hello.h:28: error: ISO C++ forbids declaration of `wxStaticText' with no type hello.h:28: error: expected `;' before '*' token hello.h:29: error: ISO C++ forbids declaration of `wxPanel' with no type hello.h:29: error: expected `;' before '*' token hello.cpp:6: error: expected `)' before '*' token hello.cpp: In member function `void MyFrame::set_properties()': hello.cpp:22: error: `wxT' was not declared in this scope hello.cpp:22: error: `SetTitle' was not declared in this scope hello.cpp: In member function `void MyFrame::do_layout()': hello.cpp:30: error: `wxBoxSizer' was not declared in this scope hello.cpp:30: error: `sizer_1' was not declared in this scope hello.cpp:30: error: `wxBoxSizer' is not a type hello.cpp:30: error: `wxVERTICAL' was not declared in this scope hello.cpp:31: error: `sizer_2' was not declared in this scope hello.cpp:31: error: `wxBoxSizer' is not a type hello.cpp:31: error: `wxHORIZONTAL' was not declared in this scope hello.cpp:32: error: `label_1' was not declared in this scope hello.cpp:32: error: `wxFIXED_MINSIZE' was not declared in this scope hello.cpp:33: error: `panel_1' was not declared in this scope hello.cpp:37: error: `wxEXPAND' was not declared in this scope hello.cpp:38: error: `SetAutoLayout' was not declared in this scope hello.cpp:39: error: `SetSizer' was not declared in this scope hello.cpp:42: error: `Layout' was not declared in this scope hello.cpp: At global scope: hello.cpp:48: error: expected class-name before '{' token hello.cpp:55: error: expected constructor, destructor, or type conversion before "bool" g++.exe: wx-config --cxxflags --libs: No such file or directory 解決方法が分かる方いらっしゃしましたらご教示頂けると幸いです。

  • エラーがとれません 助けてください

    エラーがとれません 助けてください http://cs.fit.edu/~mmahoney/dist/eval4.cpp をコンパイルすると eval4.cpp: In member function ‘bool Attack::read(FILE*)’: eval4.cpp:105: error: ‘strlen’ was not declared in this scope eval4.cpp:114: error: ‘strchr’ was not declared in this scope eval4.cpp: In function ‘int main(int, char**)’: eval4.cpp:132: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:133: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:134: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:183: error: ‘strlen’ was not declared in this scope のようなエラーがでてしまいます。 Ubuntuのg++でコンパイルしています。 なにがまずいのでしょうか?

  • gccでコンパイル時のエラー

    // test.cpp #include <stdio> using namespace std; int main(int argc, char *argv[]) { printf("test\n"); return 0; } 上記コードをコンパイルしたいのですが make -k g++ -g -O2 -Wall -I. -c test.cpp -o test.obj test.cpp:2:17: stdio: No such file or directory test.cpp: In function `int main(int, char**)': test.cpp:7: error: `printf' was not declared in this scope test.cpp:7: warning: unused variable 'printf' make: *** [test.obj] Error 1 make: Target `all' not remade because of errors. となります。 #include <stdio> using namespace std; を #include <stdio.h> // using namespace std; にすれば正常に終了するのですがなぜでしょうか? gccはMingw5.1.6からインストールしたもので、 バージョンはgcc3.4.5です。 Meadow上から実行しました。 回答よろしくお願い致します。

  • 箱庭諸島2+でコンパイルエラー

    Windows XP SP3 + GCC4.4.0を使っています。 「箱庭諸島の保管庫」というサイトから箱庭諸島2+をダウンロードしてきて、コマンドプロンプトから、解凍したディレクトリに移動し、makeを実行しました。すると、 g++ -c -O2 -Wall main.c In file included from main.c:1: main.h:5:21: error: iostream.h: No such file or directory In file included from main.h:6, from main.c:1: hako_io.h:5:20: error: fstream.h: No such file or directory In file included from info.h:7, from hako_io.h:12, from main.h:6, from main.c:1: value.h:30: error: 'ifstream' has not been declared In file included from hako_io.h:12, from main.h:6, from main.c:1: info.h:30: error: 'ifstream' has not been declared info.h:33: error: 'ofstream' has not been declared info.h:101: error: 'ifstream' has not been declared info.h:104: error: 'ofstream' has not been declared In file included from hako_io.h:14, from main.h:6, from main.c:1: map.h:32: error: 'ofstream' has not been declared map.h:35: error: 'ifstream' has not been declared map.h:185: error: 'ofstream' has not been declared map.h:188: error: 'ifstream' has not been declared In file included from hako_io.h:15, from main.h:6, from main.c:1: command.h:20: error: 'ifstream' has not been declared command.h:21: error: 'ofstream' has not been declared command.h:74: error: 'ifstream' has not been declared command.h:75: error: 'ofstream' has not been declared In file included from main.h:6, from main.c:1: hako_io.h:29: error: ISO C++ forbids declaration of 'ofstream' with no type hako_io.h:29: error: expected ';' before '*' token main.c: In function 'int main()': main.c:5: error: 'srandom' was not declared in this scope make: *** [main.o] Error 1 というエラーが出て、コンパイルされません。 原因はいったいどこにあるのでしょうか。 「ifstream」や「ofstream」といった単語が多く見られるので、そこがエラーの元だとは思うのですが… どなたか、知恵をお貸しいただけないでしょうか。

  • lunuxでコンパイル

    普段はリヌックスの環境を使っているのですが、ウィンドウズでしか動かないプログラムがあり、プログラムを実行するたびに、マシンを切り替えていて不便を感じています。 http://prefixspan-rel.sourceforge.jp/のC++のファイルをリヌックスでコンパイルしたいのですが、g++ prefixspan.cpp では In file included from /usr/include/c++/4.4/backward/strstream:47, from prefixspan.cpp:30: /usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. prefixspan.cpp: In function ‘int main(int, char**)’: prefixspan.cpp:492: error: ‘atoi’ was not declared in this scope となります。C++に関しては詳しくないのですが、これは直せるものなのでしょうか?

  • Debian玄箱にドライバコンパイル不調

    Debian lenny化 した玄箱(初代)にEPSON KOWA ( 現:エプソンアヴァシス株式会社)のプリンタドライバソースファイルをコンパイル中に errorが表示されうまく適用できません。 EPSON PM-950C用のドライバのソースファイルをコンパイル中に”./libcbt.a: could not read symbols: File in wrong format”と表示されうまくいかない まず、rpm ではなく、ソースファイル「pips950-2.5.2.tar.gz」をダウンロードし、 /usr/src/pips950-2.5.2 に展開しています。 上記のエラー「 ./libcbt.a: could not read symbols: File in wrong format 」の対処方法をご教示ください。 直前のメッセージを字数制限までコピーします。 make[3]: Entering directory `/usr/src/pips950-2.5.2/ekpd' gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd.c gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd_comserv.c cbtd_comserv.c: In function 'comserv_thread': cbtd_comserv.c:158: warning: pointer targets in passing argument 3 of 'accept' differ in signedness gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd_datatrans.c gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd_setup.c cbtd_setup.c: In function 'parameter_setup': cbtd_setup.c:85: warning: pointer targets in passing argument 4 of 'get_parameter' differ in signedness gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd_signal.c gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c cbtd_thread.c gcc -g -O2 -Wall -o ekpd cbtd.o cbtd_comserv.o cbtd_datatrans.o cbtd_setup.o cbtd_signal.o cbtd_thread.o ./libcbt.a -lpthread -ldl /usr/bin/ld: ./libcbt.a(cbtd_wrapper.o): Relocations in generic ELF (EM: 3) /usr/bin/ld: ./libcbt.a(cbtd_wrapper.o): Relocations in generic ELF (EM: 3) ./libcbt.a: could not read symbols: File in wrong format collect2: ld returned 1 exit status make[3]: *** [ekpd] Error 1 make[3]: Leaving directory `/usr/src/pips950-2.5.2/ekpd' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/usr/src/pips950-2.5.2/ekpd' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/usr/src/pips950-2.5.2' make: *** [all-recursive-am] Error 2

  • C++のreduce

    C++のreduceを使おうとすると error: 'reduce' was not declared in this scope となってしまいます reduceを使うにはどうしたらよいでしょうか? OSはMac GCCのバージョンは9.2.0_3となってます よろしくおねがいします コード #include <iostream> #include <vector> #include <numeric> using namespace std; int main() { const vector<int> v = {1, 2, 3}; int sum = reduce(v.begin(), v.end()); cout << sum << endl; }

  • WinMainのコンパイルについて

    こんにちわ。 某動画のまねをしてテトリスの作成に取り掛かっているのですが、最初から躓いてしまい困っています。 ◆現象 コンパイル時にWinMainが再宣言されているというような内容のエラーが出てしまい、コンパイルに失敗する D:\tetris>gcc -mwindows tetris.cpp tetris.cpp:18: error: `int WinMain' redeclared as different kind of symbol C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1109: error: previous declaration of `int WinMain(HINSTANCE__*, HINSTANC E__*, CHAR*, int)' tetris.cpp:18: error: declaration of `int WinMain' C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1109: error: conflicts with previous declaration `int WinMain(HINSTANCE_ _*, HINSTANCE__*, CHAR*, int)' tetris.cpp:18: error: `HINSTANSCE' was not declared in this scope tetris.cpp:18: error: expected primary-expression before "hPrevInst" tetris.cpp:18: error: expected primary-expression before "cmdLine" tetris.cpp:18: error: expected primary-expression before "int" tetris.cpp:18: error: initializer expression list treated as compound expression tetris.cpp:18: error: expected `,' or `;' before '{' token ◆環境 OS:Windows コンパイラ:MinGW ◆問題個所のソース int WinMain(HINSTANSCE hInst, HINSTANCE hPrevInst, LPSTR cmdLine, int cmdShow){ WinMainの宣言個所はここだけなのでエラーの意味がよくわからず、色々と調べてみましたが原因はよくわかりませんでした。 Win32APIについてはあまり詳しくないので(C++の原因かもしれませんが)解説できる方がいらっしゃったらご回答願います。

  • C++の問題で質問です。

    C++のストリームを用いたファイルの入出力の問題です。 #include<iostream> #include<fstream> using namespace std; int main() { ifstream fin; fin.open("test.txt"); if(!fin){ cout<<"Cannot open the file."<<"\n"; exit(1); } char str1[16]; char str2[16]; fin>>str1>>str2; cout<<"Tow words have been written!"<<"\n"; cout<<str1<<"\n"; cout<<str2<<"\n"; fin.close(); return 0; } このプログラムを実行しようとすると In function 'int main()'; 'exit' was not declared in this scope と表示されてしまいます。 どこが間違っているのでしょうか? わかる方がいらっしゃいましたらお願いします。

  • arduino due tone()について

    arduino due を使用しtone()関数を使用しようとしたところ ”tone was not declared in this scope”と表示されました。uno では使えたんですが・・・ 原因がわかる方教えてください。また、解決方法ありましたらそちらもご教授ください。

専門家に質問してみよう