help on compiling code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

help on compiling code

Post 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..
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post 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.
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

Post by asdfgh »

i am using cygwin..

the include files are .h files
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post 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.
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

these are the two files

Post by asdfgh »

help me in compiling and linking these files..
Attachments
Desktop.rar
these r the files
(891 Bytes) Downloaded 19 times
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post 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 --
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

Post by asdfgh »

these are the error messages when i assemble this file..
Attachments
ass.zip
(1021 Bytes) Downloaded 17 times
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post 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.
"Sufficiently advanced stupidity is indistinguishable from malice."
Post Reply