Page 1 of 1

help on compiling code

Posted: Fri Apr 18, 2008 9:18 pm
by asdfgh
i have three files an assembly file.
an file main.c jus to print hello
and an include file which contains print function.

how to compile it in gcc and link it..

Posted: Fri Apr 18, 2008 9:29 pm
by JackScott
http://users.actcom.co.il/~choo/lupg/tu ... -unix.html
That file (first on google!) gives background info on how to compile C programs.
http://www.osdev.org/wiki/Bare_bones
Shows you how to integrate assembly into a C project (which is probably what you are doing).
Before we can help you more, we need to know more about your project and compilation environment. Are you using Cygwin? Linux? Visual Studio 2008 Enterprise?
Also, is the include file a .c or a .h file, or something different?

Edit: Better input, better output. More info always helps. Also, if you have tried to compile it yourself, tell us what commands you used and where you got stuck. Then we can really get going.

Posted: Fri Apr 18, 2008 9:37 pm
by asdfgh
i am using cygwin..

the include files are .h files

Posted: Fri Apr 18, 2008 9:45 pm
by JackScott
You'll want to use something along the lines of the following:

Code: Select all

gcc -c source.c -o source.o
nasm -f elf -o loader.o loader.s
ld -T linker.ld source.o loader.o
If you don't have a linker.ld, use the one from the Bare Bones tutorial. You should use #include in your C source file to include the header file.

Give that a go, and report any problems you have, we'll help you sort it out. Best bet is to just try different things until one works.

these are the two files

Posted: Sat Apr 19, 2008 3:01 am
by asdfgh
help me in compiling and linking these files..

Posted: Sat Apr 19, 2008 3:24 am
by thepowersgang
Things to do:
1. Clean Up code (Indent and add a header - project name and file pourpose)
2. Create `texmem` variable (unsigned char)
3. Create clear_screen() and newline() functions
4. Compile using Yayyak's instructions and the linker.ld file from the barebones tutorial.

If you are having problems post your problem with the error messages included please.

Also, don't upload attachments in RAR format, use ZIP or tar.gz, it makes life easier for all of us.

-- Sorry if this seems condescending, I'm getting a bit tired --

Posted: Sat Apr 19, 2008 7:27 am
by asdfgh
these are the error messages when i assemble this file..

Posted: Sat Apr 19, 2008 9:43 am
by Zenith
The errors you are getting is because your assembly file is in AT&T syntax, while you're trying to compile it with NASM. Assemble it with GAS instead via GCC, like so:

Code: Select all

gcc -c source.c -o source.o
gcc -c loader.S -o loader.o
ld -T linker.ld source.o loader.o 
Note: Are you sure you're good for OSdev? From what you've said so far, it doesn't seem like you have the slightest idea what your doing. Are you proficient in C and do you know the basics of assembly? See if you have the Required Knowledge.