LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 07-31-2011, 10:46 PM   #1
iBasher
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Rep: Reputation: 0
How to compile .S (assembly) which includes a C header?


Hi! I am trying to compile a project which doesn't have a Makefile. So I am trying to compile it myself. Let's say the file structure looks like this:

Code:
main.c test.h test.S
The file test.h contains function prototypes which are called from main.c the code for these functions are written in assembly and stored in test.S

Ive never actually compiled an assembly program. I tried using:

Code:
# gcc main.c test.S -o test
-over 200 lines of warnings and errors-
How should I do this?
 
Old 08-01-2011, 03:44 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by iBasher View Post
I tried using:

Code:
# gcc main.c test.S -o test
-over 200 lines of warnings and errors-
How should I do this?
Generally, that's the correct command to use - gcc will produce object files for both the source files, and then try to link them.

Note that if you #include your test.h file in test.S, it should either not use anything that isn't valid assembly (such as function declarations) or these should be inside blocks like the following:

Code:
/* test.h */

/* Defines for both C and assembler. */
#define MY_VALUE 0x12

/* gcc predefines __ASSEMBLER__ when preprocessing assembly language */
#ifndef __ASSEMBLER__
/* Only seen by C code. */
int my_func(void);
#endif
If this doesn't help, try and deal with the very first error you get (possibly by posting it here if you don't know how to fix it) and move on from there.

Last edited by JohnGraham; 08-01-2011 at 03:47 AM.
 
Old 08-01-2011, 10:33 PM   #3
iBasher
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Original Poster
Rep: Reputation: 0
The source can be found at http://github.com/Chronic-Dev/anthrax

Last edited by iBasher; 08-03-2011 at 03:49 PM.
 
Old 08-02-2011, 01:30 AM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by iBasher View Post
I don't know about anybody else on this forum, but I don't run a code review service (at least not for free...). Just deal with the first error you get and ask for help if you need it.
 
Old 08-03-2011, 03:06 PM   #5
iBasher
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Original Poster
Rep: Reputation: 0
SOLVED IT!! I took away all unneeded functions and got rid of the '.h' for the assembly. Then I created object files for everything and linked it into a test program which prints 'Hello, World!\n'

Thnx for the help!

Last edited by iBasher; 08-03-2011 at 03:49 PM. Reason: Solved
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
compile the assembly code problem with make tools shitou Linux - Software 1 12-30-2010 09:33 AM
How to compile Assembly code in linux fedora11 ? cvr Linux - Software 18 06-23-2010 11:12 PM
Compile Error: cannot find x includes pengu Linux - Software 2 09-05-2006 03:10 PM
Can gcc cross-compile C code to M68K Assembly? lowpro2k3 Programming 1 03-25-2005 07:50 AM
where are xpm includes and librarys? to compile rxvt with backgroud support legolin Linux - Software 0 12-28-2003 10:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration