アプリ版:「スタンプのみでお礼する」機能のリリースについて

// 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上から実行しました。

回答よろしくお願い致します。

A 回答 (3件)

> gcc -g test.obj -o test.exe -lm



この部分が間違っています。
gccではなくg++を使ってください。
gccにすると、C++のためのライブラリがリンクされませんので。
    • good
    • 0
この回答へのお礼

なるほど!そうゆうことだったのですね!
ありがとうございました。

makefileをなおしてみました。

make -k
g++ -g test.obj -o test.exe -lm

Compilation finished at Sun Nov 15 14:31:55

いけました!!
これからもっと勉強します。

お礼日時:2009/11/15 14:36

> 以前 Bcc32 を使っていたときは上記コードでいけてたのですが、


> gcc固有の機能なのですか?

本質的には質問者さんのコードが間違っていますが、(gccではなく)bcc32の独自仕様です。
    • good
    • 0
この回答へのお礼

そうだったのですかbcc32の独自仕様なのですね。
ありがとうございます。

すみません。再度おしえてください。
// test.cpp
#include <iostream>
using namespace std;

int main()
{
cout << "test";
return 0;
}

上記のコードにしたのですが、今度は
make -k
g++ -g -O2 -Wall -I. -c test.cpp -o test.obj
gcc -g test.obj -o test.exe -lm
test.obj: In function `main':
d:/Project/独習C/test.cpp:7: undefined reference to `std::cout'
d:/Project/独習C/test.cpp:7: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.obj: In function `Z41__static_initialization_and_destruction_0ii':
c:/Gnu/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iostream:77: undefined reference to `std::ios_base::Init::Init()'
c:/Gnu/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iostream:77: undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status
make: *** [test.exe] Error 1
make: Target `all' not remade because of errors.
となりました。

やはりコードが間違っているのでしょうか。
未熟物なのですみませんおしえてください。

お礼日時:2009/11/15 14:03

#include <cstdio>


using namespace std;

でどうぞ。
    • good
    • 0
この回答へのお礼

早速の回答ありがとうございます。
やってみたところ確かにできました!!

以前 Bcc32 を使っていたときは上記コードでいけてたのですが、
gcc固有の機能なのですか?

お礼日時:2009/11/15 13:35

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!