What is wrong with this C++ code?

What is wrong with this C++ code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <string>

int main (int argc, char **argv)
{
   std::string command = "open -a kate";
   if(argc > 1) {
      command += std::string(argv[1]);   
   }
   //system(command);
   printf("%s", command.c_str());

   return(0);
} 


error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
macbook:~ rain$ gcc TextEdit.cpp -o TextEdit
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      _main in TextEdit-bdacab.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long)", referenced from:
      _main in TextEdit-bdacab.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      _main in TextEdit-bdacab.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in TextEdit-bdacab.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in TextEdit-bdacab.o
  "___gxx_personality_v0", referenced from:
      _main in TextEdit-bdacab.o
      Dwarf Exception Unwind Info (__eh_frame) in TextEdit-bdacab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
macbook:~ rain$
Use g++ instead of gcc when compiling C++ code.
Topic archived. No new replies allowed.