Страница 1 из 1

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

Добавлено: 28 апр 2006, 10:54
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

Добавлено: 28 апр 2006, 10:59
Gnida
я конечно не помню что там точно в спп , но может либа iostream.h называеца?

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

main() {}

Добавлено: 28 апр 2006, 11:05
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]$

Добавлено: 28 апр 2006, 11:25
Llama
Silos, g++ ?

Добавлено: 28 апр 2006, 11:30
exe
c++ самое то.

Добавлено: 28 апр 2006, 11:53
Silos
Так скомпилилось, спасибо. Хотя на FC3 gcc компилилось.

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

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

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