gcc не компилит c++ исходники

Все о программировании под *nix
Аватара пользователя
Silos
Неотъемлемая часть форума
Сообщения: 287
Зарегистрирован: 15 фев 2004, 19:04
Откуда: Belarus, Minsk
Контактная информация:

gcc не компилит c++ исходники

Сообщение Silos »

Такая проблемка появилась: когда пытаюсь скомпилировать C++ исходник

Код: Выделить всё

#include <iostream>
using namespace std;

int main()
{
        cout << "Hello\n";
        return 0;
}

вылазит это:

Код: Выделить всё

[silos@asakura test]$ gcc main.cpp
/tmp/cc0bXYoP.o: In function `__static_initialization_and_destruction_0(int, int)':main.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/cc0bXYoP.o: In function `__tcf_0':main.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc0bXYoP.o: In function `main':main.cpp:(.text+0x8e): undefined reference to `std::cout'
:main.cpp:(.text+0x93): 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*)'
/tmp/cc0bXYoP.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Код: Выделить всё

[silos@asakura test]$ gcc -x c++ -o test main.cpp
/tmp/ccKq7mGP.o: In function `__static_initialization_and_destruction_0(int, int)':main.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccKq7mGP.o: In function `__tcf_0':main.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccKq7mGP.o: In function `main':main.cpp:(.text+0x8e): undefined reference to `std::cout'
:main.cpp:(.text+0x93): 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*)'
/tmp/ccKq7mGP.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
То, что у меня стоит:

Код: Выделить всё

[silos@asakura test]$ gcc --version
gcc (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[silos@asakura test]$ uname -a
Linux asakura.org 2.6.16-1.2096_FC5 #1 Wed Apr 19 05:14:36 EDT 2006 i686 athlon i386 GNU/Linux

Gnida
Неотъемлемая часть форума
Сообщения: 346
Зарегистрирован: 04 апр 2004, 22:38

Сообщение Gnida »

я конечно не помню что там точно в спп , но может либа iostream.h называеца?

попробуй скомпилировать

main() {}
С опытом ошибки не изчезают , а умнеют

Аватара пользователя
Silos
Неотъемлемая часть форума
Сообщения: 287
Зарегистрирован: 15 фев 2004, 19:04
Откуда: Belarus, Minsk
Контактная информация:

Сообщение Silos »

Так оно скомпилилось.
Хедер называется iostream.h, но обращаться к нему надо как iostream.

Код: Выделить всё

[silos@asakura test]$ echo 'main() {}' > main2.cpp
[silos@asakura test]$ gcc -o test2 main2.cpp
[silos@asakura test]$ vim main.cpp
[silos@asakura test]$ gcc -o test main.cpp
In file included from /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/backward/iostream.h:31,
                 from main.cpp:1:
/usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/backward/backward_warning.h:32:2: warning: #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> header for C++ includes, or <iostream> instead of the deprecated header <iostream>. To disable this warning use -Wno-deprecated.
/tmp/ccuMP04V.o: In function `__static_initialization_and_destruction_0(int, int)':main.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccuMP04V.o: In function `__tcf_0':main.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccuMP04V.o: In function `main':main.cpp:(.text+0x8e): undefined reference to `std::cout'
:main.cpp:(.text+0x93): 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*)'
/tmp/ccuMP04V.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[silos@asakura test]$

Аватара пользователя
Llama
Неотъемлемая часть форума
Сообщения: 9749
Зарегистрирован: 06 фев 2002, 11:40
Откуда: Менск

Сообщение Llama »

Silos, g++ ?
Опыт растет прямо пропорционально выведенному из строя оборудованию

Аватара пользователя
exe
Неотъемлемая часть форума
Сообщения: 860
Зарегистрирован: 28 ноя 2003, 21:08
Откуда: Минск

Сообщение exe »

c++ самое то.

Аватара пользователя
Silos
Неотъемлемая часть форума
Сообщения: 287
Зарегистрирован: 15 фев 2004, 19:04
Откуда: Belarus, Minsk
Контактная информация:

Сообщение Silos »

Так скомпилилось, спасибо. Хотя на FC3 gcc компилилось.

Код: Выделить всё

[silos@asakura test]$ g++ -o test main.cpp
[silos@asakura test]$ c++ -o test main.cpp
[silos@asakura test]$
А чем `с++` от `g++` отличается, или это один и тотже бэкенд к gcc?

Аватара пользователя
exe
Неотъемлемая часть форума
Сообщения: 860
Зарегистрирован: 28 ноя 2003, 21:08
Откуда: Минск

Сообщение exe »

Похоже что на линковке gcc не подключает с++ библиотеки,
в твоем случае iostream. Я дальше не копал, просто использую
с++ и все.

Ответить