help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: library problem - my own version of C++ using gcc does not link


From: Robert Heller
Subject: Re: library problem - my own version of C++ using gcc does not link
Date: Thu, 24 May 2007 19:39:33 +0200

At Thu, 24 May 2007 15:08:26 GMT Jim Anderson <ezjab@ieee.org> wrote:

> 
> Paul Pluzhnikov wrote:
> > Jim Anderson <ezjab@ieee.org> writes:
> > 
> >> I tried compiling a C++ program that I have. All of the
> >> C++ files compile ok, but during the linking phase,
> >> I get numerous error messages. The first of which is:
> >>
> >>  >>> test.o: In function
> >>  >>> 
> >> `__static_initialization_and_destruction_0':/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iostream:76:
> >>  >>> undefined reference to `std::ios_base::Init::Init()'
> > 
> > The first question is: what's your failing link line?
> > Always use correct compiler driver (g++ for C++ code) when compiling
> > and linking. IOW, do not do this:
> > 
> >   gcc main.cpp
> > 
> > do this instead:
> > 
> >   g++ main.cpp
> > 
> >> It looks to me like the libraries are not being found right.
> > 
> > Possible, but less likely than the "user mistake" above.
> > 
> > Cheers,
> 
> Paul,
> 
> The link line is:
> 
>  >>   gcc -g -o test test.o Product.o DerivedProduct.o Creator.o 
> DerivedCreator.o
> 
> I used gcc because when I downloaded g++, the tarball did not
> appear to have a complete set of code to build g++.
> 
> At one time, didn't gcc compile and link C++ code? I do think it
> is strange that gcc will compile C++ code, but not link it.

gcc can link C++ code, but you need to give it a 'hint' that you are in
fact linking C++ code, usually by including the -l option(s) that g++
would normally add:

gcc -g -o test test.o Product.o DerivedProduct.o Creator.o \
        DerivedCreator.o -lstdc++ -lc++

Or something like that -- like most people I use g++ to link C++ code, so
I don't need to add the extra -l options.

> 
> If I can figure out how to build g++, I'm more than happy to use
> g++. I tried using the installed g++ on my system and it linked
> the *.o files compiled by gcc just fine. So guess I'm home free.

You may have linked with the wrong libraries...

> 
> I appreciate your help but if you can shed light on why gcc
> compiles C++ but does not link it, I'm curious to know why.
> Personally, I think too much is included in gcc. IMHO, gcc should
> compile C files, g++ for C++, etc.
> 
> Regards,
> Jim
>                                                                               
>  

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Linux Installation and Administration
http://www.deepsoft.com/  -- Web Hosting, with CGI and Database
heller@deepsoft.com       -- Contract Programming: C/C++, Tcl/Tk
                         


reply via email to

[Prev in Thread] Current Thread [Next in Thread]