LINUX.ORG.RU

Найдите ошибку в ПРОСТЕЙШЕЙ программе я сдался :((


0

0

Найдите ошибку в ПРОСТЕЙШЕЙ программе я сдался :((

#include <string>
int main()
{
  std::string s;
  return 0;
}

gcc 123.cpp

ВЫДАЁТ ВОТ ЭТО

/tmp/ccXrJo03.o: In function `basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::Rep::copy(unsigned int, char
const *, unsigned int)':
/tmp/ccXrJo03.o(.basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::Rep::gnu.linkonce.t.copy(unsigned int, cha
r const *, unsigned int)+0x27): undefined reference to `string_char_traits<char>::copy(char *, char const *, unsigned int)'
/tmp/ccXrJo03.o: In function `__malloc_alloc_template<0>::_S_oom_malloc(unsigned int)':
/tmp/ccXrJo03.o(.__malloc_alloc_template<0>::gnu.linkonce.t._S_oom_malloc(
unsigned int)+0x1a): undefined reference to `endl(ostream &)'
/tmp/ccXrJo03.o(.__malloc_alloc_template<0>::gnu.linkonce.t._S_oom_malloc(
unsigned int)+0x27): undefined reference to `cerr'
/tmp/ccXrJo03.o(.__malloc_alloc_template<0>::gnu.linkonce.t._S_oom_malloc(
unsigned int)+0x2c): undefined reference to `ostream::operator<<(ch
ar const *)'
/tmp/ccXrJo03.o(.__malloc_alloc_template<0>::gnu.linkonce.t._S_oom_malloc(
unsigned int)+0x37): undefined reference to `ostream::operator<<(os
tream &(*)(ostream &))'
collect2: ld returned 1 exit status


anonymous

gcc -lstdc++ -o my_coolest_app 123.cpp

И еще, main правильно объявлять так:

int main(int argc, char *argv[])

Твое объявление совместимо не со всеми компиляторами.

asso_w
()
Ответ на: комментарий от alphex_kaanoken

Это почему? По моему это одно и то же.

anonymous
()
Ответ на: комментарий от asso_w

>Твое объявление совместимо не со всеми компиляторами.

по стандарту должно быть совместимо со всеми.

ISO/IEC 9899:1999 (E) ©ISO/IEC 5.1.2.2.1 Program startup 1 The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /* ... */ } or equivalent;9) or in some other implementation-defined manner.

Reset ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.