LinuxでのC++プログラムのコンパイルに関する問題

このQ&Aのポイント
  • 普段はLinuxの環境を使っているが、特定のプログラムがWindowsでしか動かないため、切り替えが不便。
  • Linuxでhttp://prefixspan-rel.sourceforge.jp/のC++ファイルをコンパイルしたいが、エラーが発生。
  • 具体的なエラーメッセージが'atoi was not declared in this scope'で、修正方法は不明。
回答を見る
  • ベストアンサー

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++に関しては詳しくないのですが、これは直せるものなのでしょうか?

noname#182748
noname#182748

質問者が選んだベストアンサー

  • ベストアンサー
回答No.3

直せます。 prefixspan.cppをemacsなどのエディタで開き、 #include <set> の下に、 #include <cstdlib> を追加しましょう。

noname#182748
質問者

お礼

回答ありがとうございます。ものすごい労力の節約になりました。本当に助かりました。

その他の回答 (2)

  • Tacosan
  • ベストアンサー率23% (3656/15482)
回答No.2

プログラムは読んでないから知らんけど, 本当に strstream を #include してるならそれは時代遅れなので sstream に変更すべし. あと atoi については stdlib.h (もしくは, あるいはむしろ cstdlib).

noname#182748
質問者

お礼

回答ありがとうございました。

  • alwen25
  • ベストアンサー率21% (272/1253)
回答No.1

私もC、C++の初心者で詳しいことは分かりませんが、 atoiについては、C++ではなくCのエラーだということが 分かります。 ascii to integerという関数です。 インクルードファイルを宣言しておけばいいのではないでしょうか。 #include <string.h>でしょうか。 最近のlinuxのソースはmakeによる、依存関係指定 自動コンパイルを使っているものが多くて、開発環境が 変わるとMakefileを書き換えなければならず 私もうまくコンパイルできません。 また、URLをクリックしても文字化けして読めません。 的外れだったら済みません。

noname#182748
質問者

お礼

回答ありがとうございました。

関連するQ&A

  • C++でコンパイルするとwarningが出ます

    C++初心者です。 C++でコンパイルすると以下のようなwarningメッセージが出るのですが、どういう意味なんでしょうか?解決策があれば教えてください。 プログラム(sample.cpp) #include <iostream.h> main(){ cout << " sample \n"; } warningメッセージ In file included from /usr/include/c++/3.3.1/backward/iostream.h:31, from sample.cpp:1: /usr/include/c++/3.3.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider usin g one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <s stream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated

  • backward_warning.hによる警告

    こんにちは。 独自で作成した、C:\Emacs_for_Windows\My_C++_Header_for_Bash.hというファイルパスを持つヘッダファイルをインクルードしているC++のソースファイルのtest.cppを、Cygwinのbash上で、g++コマンドを使い、 g++ test.cpp のようにビルドしたところ、以下のような警告が出ました。 ------------------------------------------------------------ bin/../lib/gcc/i686-pc-cygwin/4.3.4/include/c++/backward/strstream:51 から include されたファイル中, C:\Emacs_for_Windows\My_C++_Header_for_Bash.h:35 から, test.cpp:2 から: /bin/../lib/gcc/i686-pc-cygwin/4.3.4/include/c++/backward/backward_warning.h:33:2: 警告: #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. ------------------------------------------------------------ Borland C++ Compiler 5.5 のbcc32コマンドでは、こういった警告は出ません。 /bin/../lib/gcc/i686-pc-cygwin/4.3.4/include/c++/backward/backward_warning.h:33 を参考に、backward_warning.hの33行目以降をみると、以下のようになっていました。 ------------------------------------------------------------ #ifdef __DEPRECATED 33 #warning \ 34 This file includes at least one deprecated or antiquated header which \ 35 may be removed without further notice at a future date. Please use a \ 36 non-deprecated interface with equivalent functionality instead. For a \ 37 listing of replacement headers and interfaces, consult the file \ 38 backward_warning.h. To disable this warning use -Wno-deprecated. ------------------------------------------------------------ どうやら「__DEPRECATED」が定義されているので、こういった警告が出ているようなのですが、 __DEPRECATEDの意味が分かりません。 警告の指示通り、-Wno-deprecatedを付けたままC++開発を続けて問題ないのでしょうか? ちなみに、C:\Emacs_for_Windows\My_C++_Header_for_Bash.hの内容は以下の通りです。 ------------------------------------------------------------ #ifndef MYHEADER_H #define MYHEADER_H //C言語のヘッダファイル #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <time.h> #include <math.h> #include <stddef.h> //C++言語のヘッダの標準識別子 #include <iostream> #include <fstream> #include <cctype> #include <cstring> #include <cstdlib> #include <ctime> #include <cstdio> #include <new> #include <iomanip> #include <strstream> #include <typeinfo> //STLに関するヘッダ #include <string> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <numeric> #include <cassert> #include <iterator> //namespaceの解決 using namespace std; #endif ------------------------------------------------------------ 以上の件について何かご存知の方がいらっしゃれば、是非教えて頂きたいと思います。 では、よろしくお願い致します。

  • iostreamについて

    今までOSはTurbo Linux 7を使っていましたが、最近RedHatLinux9にかえました。 それで、今までは普通に出来ていたことが出来なくなったので質問します。どちらかと言うとプログラム系の亊ですけど、Windowsではこんなことは起きないのでここで質問します。 C++でプログラムを作っているのですけど、 プログラム中で<iostream.h>,<fstream.h>をインクルードしていて、コンパイルすると /usr/include/c++/3.2.2/backward/fstream.h:31 から include されたファイル中, stereo_draw.cpp:4 から: /usr/include/c++/3.2.2/backward/backward_warning.h:32:2: 警告: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. と言うエラーメッセージが出るのです(stereo_draw.cppは私の作ったソースファイル)。 英語が得意ではないので訳があやしいですが、 『このファイルは推奨してない、または古いヘッダーをインクルードしています。C++スタンダードセクション17.4.1.2中の32ヘッダーのいづれかを使うことを推めます。例えば<X.h>の代わりにC++インクルード用の<X>ヘッダーをインクルードするとか、非推奨の<strstream.h>の代わりに<sstream>を使うなど』 と言っているのではないかと思います。でも、セクション17.4.1.2の32個のヘッダーなんて知らないです。それに、Turboの時はこんなメッセージは出ませんでした。 これを解決する方法をどなたか知っていたら教えて下さい。

  • clock関数のコンパイルエラーで

    こんにちは。 C++プログラムの実行時間計測リスト #include<iostream.h> #include<time.h> int main(void){ clock_t start_time=clock(); int i; //ココから //計測したい処理を書く //ココまで cerr<<clock()-start_time<<"マイクロ秒"<<endl; return 0; } をRedHat9上でコンパイルしようとすると $gcc -o clock clock.cc /usr/include/c++/3.2.2/backward/iostream.h:31 から include されたファイル中, clock.cc:1 から: /usr/include/c++/3.2.2/backward/backward_warning.h:32:2: 警告: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. /tmp/ccoZe32a.o(.text+0x1c): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' /tmp/ccoZe32a.o(.text+0x3b): In function `main': : undefined reference to `std::cerr' /tmp/ccoZe32a.o(.text+0x40): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(long)' : collect2: ld はステータス 1 で終了しました となってしまいます。これはどうすればコンパイルできるようになるのでしょうか?

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

    エラーがとれません 助けてください 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ですが、コンパイルができません!

    以下のプログラムですが #include <stdio.h> int main() { Int col; char i; scanf( "%d", &col ); for( i = 0 ; i < 26 ; i++ ){ if( i > 0 && ( i % col ) == 0 ) printf( "\n" ); printf( "%c", 'a' + i ); } return 0; } 以上のプログラムをgccでコンパイルしました。 コンパイルするために入力した文字→  gcc p.c -o p.exe 以下のエラーがでてコンパイルできません。 p.c: In function `main': p.c:4: error: `Int' undeclared (first use in this function) p.c:4: error: (Each undeclared identifier is reported only once p.c:4: error: for each function it appears in.) p.c:4: error: syntax error before "col" p.c:7: error: `col' undeclared (first use in this function) p.c:17:2: warning: no newline at end of file  以上なぜコンパイルができないのですか? よろしくお願いいたします。

  • 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上から実行しました。 回答よろしくお願い致します。

  • octaveのコンパイルオプション

    MATLABのクローンのoctaveを, C++のライブラリとして利用したいと考えているのですが, コンパイルが上手くいきません. プログラムは以下のような単純なものです. --------- begin of hello.cpp ------------------ #include<iostream> #include<octave/config.h> #include<octave/Matrix.h> int main(){ Matrix m(2,2,1.0); cout<<"hello octave !"<<m; return 0; } --------- end of hello.cpp -------------------- 次のようなコンパイルオプションでコンパイルしています. > g++ -I/usr/include/octave-2.1.35/ -L/usr/lib/octave-2.1.35 \ -loctave -lcruft -loctinterp -lreadline -lcurses -llapack \ -lblas -ldl -lg2c -L/home/pippin/name/.redhat/SOURCES/octave-2.1.35/kpathsea \ -lkpathsea hello.cpp すると,次のようなエラーメッセージを返されます. /tmp/ccuvk2IV.o: In function `main': /tmp/ccuvk2IV.o(/text+0x2c): multiple definition of `main' /usr/lib/gcc-lib/i386-redhat-linux/2.96/libg2c.a(main.o)(.text+0x0): first definition here /usr/bin/ld: Warning: size of symbol `main' changed from 58 to 174 in /tmp/ccuvk2IV.o collect2: ld returned 1 exit status エラーメッセージから解するに,libg2c.aでもmain関数が定義されているため, hello.cppのmain関数とかぶるという様な事だと思うんですが,ライブラリに main関数が定義されているというのも変な話です. ちなみに,コンパイルした環境は, OS: redhat linux 7.3 octave version 2.1.35 gcc version 2.96 このタイプのエラーを回避する方法を知っておられる方は, 回答の方よろしくお願いします.

  • 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

  • Ubuntu feisy fawnでGTK+のプログラミングのコンパイルにて

    Ubuntu feisty fawnでGTK+とgccを使ってプログラミングをしたいのですが、コンパイルで手間取ってしまいました。 ソース #include <gtk/gtk.h> int main(int argc,char *argv[]){ GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_show(window); gtk_main(); return 0; } インストールしたパッケージ libgtk-2.0 pkg-config0.21-1build1 gcc-4.1 gcc-4.1-base これをコンパイルするときに cc -o base base.c 'pkg-config --cflags --libs gtk+-2.0' でやると cc: pkg-config --cflags --libs gtk+-2.0: No such file or directory base.c:1:21: error: gtk/gtk.h: No such file or directory base.c: In function ‘main’: base.c:4: error: ‘GtkWidget’ undeclared (first use in this function) base.c:4: error: (Each undeclared identifier is reported only once base.c:4: error: for each function it appears in.) base.c:4: error: ‘window’ undeclared (first use in this function) base.c:8: error: ‘GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function) ちなみに単体でpkg-config --cflags --libs gtk+-2.0でコマンドを打った場合、 -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 となっていました。 どなたか解決方法をご存知のかたはいませんでしょうか?

専門家に質問してみよう