SUMMARY: compiling .s files

From: Greg (G-tech Corp.) (
Date: Tue Dec 03 1996 - 17:09:09 CST

Kevin Davidson

} When I attempt to compile any assembler programs on my
} 2.5.1 machines, I am always greeted with the following;
} >> gcc multi.s -o multi
} Undefined first referenced
} symbol in file
} main /usr/local/lib/gcc-lib/sparc-sun-solaris2/2.4.5/crt1.o
} ld: fatal: Symbol referencing errors. No output written to multi
} This also happens with SPARCcompiler but of course the path to
} crt1.o is different. The same scenario does not exist with
} C program compiles. I checked the FAQ, and confirmed all the
} proper Solaris pkgs are installed as was pointed out in one of
} the questions.
} Anyone experience this or know how I can get this straightened
} out?

*now* I realize it was a stupid question. We ran outta turkey
and ate my brain. The simple answer was lack of a main, which I
had written twice as _main. Not sure how I got in that habit,
but I appreciate the quick answers and surprisingly lack of flames.

crt1.0 calls main, which is what a normal C program declares as its
entry point. You should:

a) not use crt1.o, which is mean as the C Run Time, and you're not C...
b) declare a main in your code as the entry point.
 this would work if multi.s defined a complete program, but since
there is no main() function, it is not a complete program. usually
the .s file will be compiled into a .o file, and then linked with some
other .o files to create the final executable program. to get the .o
file from .s file, use

        gcc -c multi.s

same with the sun cc.
 crt stands for C RunTime. Its a small section of machine code that
sets up stacks and variables and then jumps to __main. main(), of
course is the top level function in any C program.

 Your assembly code needs to be either standalone, so it is not linked
with crt1.o or you need to have an entry point called __main.
Why are you writing assembly programs ?
You need to have a symbol "main" define in your program.
If you compile with a C compiler, then the source could must have a "main"
routine defined. Part of the "C" linking is to link in crt1.o as the
header, and this header tries to call "main". This is how C programs
get started and how
  int main(int argc,char *argv[])
gets called.

Your .s file doesn't have a "main" defined, and so isn't a complete program
suitable for linking in C. It may be suitable for converting to a .o file
for later inclusion in a program.... "man as" for details.
You problem is you forgot to write a main() function in your assembly program,
because C compiler need that,just add a main() or _main() function in your
assembly program and have a try.


This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:17 CDT