LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-31-2007, 03:10 AM   #1
atalmapi
LQ Newbie
 
Registered: Jan 2007
Posts: 1

Rep: Reputation: 0
cc, as and ld


Hello,
I have to compile a program using cc, as and ld.
Here is the program :

Code:
#include <stdio.h>
long int factorielle(int n) {
 if (n<2)
 return 1;
 else
 return n*factorielle(n-1);
}

int main(int argc, char *argv[]){
 int i;
 printf("Hello World!\n\n");
 for(i=0;i<10;i++)
  printf("%i! = %li\n",i,factorielle(i));
 return 0;
}
I use the folowing commands :
Code:
cc -c -S toto.c
as -o toto.o toto.s
No problem at this point, but the use of ld become complicated. I succeded using it like that:

Code:
ld -o toto /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o /usr/lib/libc.so toto.o
No errors appears but it's impossible to execute the resulting program toto (of course I made a chmod).

I absolutely need to use cc, as and ld : can someone help me ?

Thanks for all...
 
Old 01-31-2007, 04:43 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
To help you better, it would be useful to know why you need to use cc, as, and ld, instead of just cc without the -c switch.
 
Old 01-31-2007, 05:48 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
well, how does it fail?

first try make toto as per normal usage (no makefile needed)
and see if the resultant prog works.

I did this:
Code:
billym.primadtpdev>make toto
gcc     toto.c   -o toto
billym.primadtpdev>toto
Hello World!

0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880

Last edited by bigearsbilly; 01-31-2007 at 05:50 AM.
 
Old 01-31-2007, 06:46 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Something like this:

Code:
ld -dynamic-linker /lib/ld-linux.so.2 -o toto /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.1.2/crtbegin.o /toto.o -lc /usr/lib/gcc/i486-linux-gnu/4.1.2/crtend.o /usr/lib/crtn.o
It depends on the version of binutils.

Quote:
/tmp$ ./toto
Hello World!

0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880

Last edited by nx5000; 01-31-2007 at 06:47 AM.
 
  


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



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

All times are GMT -5. The time now is 05:03 AM.

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