LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-07-2002, 11:27 PM   #1
wsimmons
LQ Newbie
 
Registered: Sep 2001
Posts: 10

Rep: Reputation: 0
Smile creating a flat binary file with gcc


Consider the simplest program which I would like to compile as a simple binary file without headers:

#include <stdio.h>

int main()
{
printf("Test file\n");
return 0;
}

The reason that I would like to compile it as a binary is so that I can experiment with LILO and mkbootdisk (or other equivalents), place the file on a floppy, and watch the prgress of the "boot" process.

When I compile and link using:

gcc -o test.bin input.c

everything works fine and just running the "program" ( ./test.bin ) produces the desired results. However when I try the following:

gcc -c input.c

ld input.o -o test.bin -oformat binary

I get an error that states that printf() is an undefined function. This is confusing. gcc -c should take it through preprocessing and compiling up to the point of linking. Why wasn't the include statement preprocessed? Or... what is the answer...where is my thinking incorrect?
How do I correct this? Also, while you are here...do you have any suggestions for getting the file to the correct position on a floppy (and to a correct position in memory when loaded) and direct LILO to also load the correct loader commands to the MBR?
 
Old 01-08-2002, 04:50 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
That's because printf is part of libc which is usually a shared library since lots of programs use it. And I don't think you want to include a static version of libc in your binary file. Which on my system is almost 1 MB.

Anyways you might want to read some stuff on this site:
http://linuxassembly.org

I think that's kind of the direction you want to go. Look at the asmutils they seem kinda nice.
 
Old 01-08-2002, 11:33 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,532
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
Which on my system is almost 1 MB.
gcc -O2 -static -o crap crap.c (aprox 1.6Mb)
strip crap (aprox 360Kb)
upx -9 crap (leaves 153Kb)

just my 2 cents,
upx btw is a freeware,no-performance-blocking exe compressor
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating binary RPMS statically! Sunilsbjoshi Linux - Software 2 10-12-2005 12:10 AM
need binary gcc phoenix_wolf Linux - Software 1 12-02-2004 03:16 AM
Making VSAM file from a flat file in AIX Raghothaman AIX 2 08-25-2004 04:55 PM
gcc and creating a debug file xviddivxoggmp3 Programming 5 03-16-2004 03:38 PM
Flat File QC Scripting mychl Programming 5 02-20-2004 11:53 AM


All times are GMT -5. The time now is 01:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration