0
0

g++とgccの導入でこけた話

Posted at

ものすごいシンプルなコード

test.cpp

#include <iostream>

using namespace std;

int main(){

  int a,c = 0;
  if(a==1)
  {
    c = 1;
  }
  else
  {
    c =2;
  }
  std::cout << "Hello world." << std::endl;
  
  return 0;
}

gccでビルド


hoge@hoge:~/lab/unit_test$ gcc -o test test.cpp
/usr/bin/ld: /tmp/ccrc3xcA.o: warning: relocation against `_ZSt4cout' in read-only section `.text'
/usr/bin/ld: /tmp/ccrc3xcA.o: in function `main':
test.cpp:(.text+0x36): undefined reference to `std::cout'

g++でビルド


hoge@hoge:~/lab/unit_test$ g++ -o test test.cpp
->OK

gccは標準ライブラリをリンクしてくれないという教訓。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0