[gnu.g++] Build g++-1.36.4 on SUN: ___main undefined

lin@cs.wmich.edu (Lite Lin) (02/05/90)

Hello, 

    I'm trying to build g++-1.36.4 with gcc-1.36.93 on a SUN 3/60
running 4.0.1.  I do use gas and gld, the latter was built from
ld.c in the g++-1.36.4 distribution.  I did not see any problem when 
I compiled gcc-1.36.93, nor did I see anything wrong when I compiled 
g++ and libg++.a.  However, when it came to the time to load
the object code produced, I got the message "Undefined symbol ___main 
referenced from the text segment".  

    A couple of notes about the procedures that I used: (1) none of
the above is installed in standard directories, but I don't think
that was a problem, as I used '-B', '-I' and '-L' flags extensively;
(2) when building gcc-1.36.93, (I believe) the native assembler 
assembler was used with 'cc' while gas was used with gcc; the native
loader was used because gld was not yet available before g++ was 
built; (3) when buiding g++, the line with MALLOC was commented, 
'crt0+.o' was added to the target 'all'.  I ran 'config.g++ sun3-os4', 
and made tm.h link to ./config/tm-sun3+.h, which is the same as tm-sun3.h 
except crt0.o's are changed to crt0+.o's.  I did *not* make config.h 
link to xm-sunos4.h as suggested in the info file because it simply
isn't there.  Hence xm-m68k.h was used and 
#define LINK_SPEC "%{!e*:-e start} -dc -dp %{g:-Bstatic} %{static:-Bstatic} %{-Bstatic}"
(4) libg++.a was built with "XTRAFLAGS = -DNO_GNULIB3 -DNO_LIBGXX_MALLOC";
the reason for using the 1st macro was because I already had crt0+.o,
if I used gnulib3 in libg++ I would get "__do_global_init" and 
"__do_global_cleanup" multiply defined; the reason for using the 2nd
macro was to be consistent with what I used for gcc and g++.  

    A copy of a most simple "hello" program, output of the compilation 
and the assembly code produced from this program are appened at the end 
of this message.  Before that, let me have another question about g++.
The following is from the Makefile for g++:
# Note: If you have SunOS 4.0, you can't use GNU LD to link programs
# which use shared libraries.  You could add -DNO_GNU_LD to this
# command line, but be warned that collect is not really powerful
# enough to do right by all C++ static constructors, and it would
# be better if you could just add support to GNU LD to handle
# shared libraries.
Since I do use SunOS 4.0.1, I'm wondering how this would affect me.
I tried to make 'collect' but failed because COLLECT_LIBS="-lld";
that was not found.  I'm also wondering how I can "add support to
GNU LD to handle shared libraries".

    As I'm an inexperienced 1st year grad student, I'd be most grateful
if someone would kindly point me to the right direction.  Replies
by either email or following up in these newsgroups will be fine.
Thank you very much.

	Lite


PS.  The simple program, its compilation output and assembly code follow:
(I forgot to change the program, but I did make a link of libg++
to libg++-1.36.3; also, the compilation output showed that the system's
gcc-cpp (earlier version, also 1.36) was used; I tried to use the newly
produced cpp with the same result; and a final question: what is the macro
GNUG for?)
-------------------------------------------------------------------------
s307% cat try.cc
#include "/usr/local/gnu/g++-1.36/libg++/g++-include/stream.h"

main(){
  cout << "Hello,World!\n";
}
s307%
s307%
s307%
s307% g++ -v try.cc
g++ version 1.36.4 (based on GCC 1.36.93)
 /usr/local/lib/gcc-cpp -+ -v -I/usr/local/gnu/g++-1.36/libg++-1.36.3/g++-include -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 try.cc /usr/tmp/cca04098.cpp
GNU CPP version 1.36
 /usr/local/gnu/g++-1.36/g++/cc1plus /usr/tmp/cca04098.cpp -quiet -dumpbase try.cc -version -o /usr/tmp/cca04098.s
GNU C++ version 1.36.4 (based on GCC 1.36.93) (68k, MIT syntax) compiled by GNU C version 1.36.93.
default target switches: -m68020 -mc68020 -m68881 -mbitfield
 /usr/local/gnu/g++-1.36/g++/as -mc68020 -o try.o /usr/tmp/cca04098.s
 /usr/local/gnu/g++-1.36/g++/ld -e start -dc -dp /usr/local/gnu/g++-1.36/g++/crt0+.o /lib/Mcrt1.o -L/usr/local/gnu/g++-1.36/libg++-1.36.3/src try.o -lg++ /usr/local/lib/gcc-gnulib -lc -L/usr/lib/f68881
try.o: Undefined symbol ___main referenced from text segment
s307%
s307%
s307%
s307% g++ -S try.cc
s307% cat try.s
#NO_APP
gcc_compiled.:
.text
        .even
LC0:
        .double 0r0.00000000000000000000e+00
LC1:
        .ascii "Hello,World!\12\0"
        .even
.globl _main
_main:
        link a6,#0
        moveml #0x3800,sp@-
        jbsr ___main
        movel d0,d0
        movel #_cout,d2
        movel #LC1,d3
        clrl d4
        tstl _cout+4
        jne L844
        pea LC1
        movel _cout,sp@-
        jbsr _sputs__9streambufPCc
        movel d0,d0
        addqw #8,sp
        moveq #-1,d1
        cmpl d0,d1
        jeq L844
        jra L843
L844:
        moveq #1,d4
L843:
        tstl d4
        jeq L846
        moveq #2,d0
        orl d0,_cout+4
L847:
L846:
        movel #_cout,d0
        jra L845
L845:
        jra L842
L842:
        clrl d0
        jra L841
L841:
        moveml a6@(-12),#0x1c
        unlk a6
        rts
----------------------------------------------------------------------------

-- 
    We hold these truths to be self-evident, that all men are created
equal, that they are endowed by their Creator with certain unalienable
Rights, that among these are Life, Liberty and the pursuit of Happiness.
                                     -- Declaration of Independence