LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-20-2009, 10:26 PM   #1
Jetfire29
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
C & C++ header files?


I'm working on some programs that I brought over from a different linux machine, and am trying to compile and run them. They compile just fine, but when I try to export them (ld -o sample sample.o, not sure what that's called), it gives me a bunch of errors about things that are not defined, like fscanf, fprintf, stdout, those things. I installed build-essential, and g++, but neither one is working, so I'm assuming stdio.h is not found. What can I do to get this file?

here's what it puts out for this one test program.
Code:
ld -o ATM ATM.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
ATM.o: In function `main':
ATM.c:(.text+0x62): undefined reference to `stdout'
ATM.c:(.text+0x76): undefined reference to `fwrite'
ATM.o: In function `get_pin':
ATM.c:(.text+0x90): undefined reference to `stdout'
ATM.c:(.text+0xa4): undefined reference to `fwrite'
ATM.c:(.text+0xab): undefined reference to `stdin'
ATM.c:(.text+0xbe): undefined reference to `fscanf'
ATM.c:(.text+0xd9): undefined reference to `stdout'
ATM.c:(.text+0xed): undefined reference to `fwrite'
ATM.o: In function `get_trans_num':
ATM.c:(.text+0x121): undefined reference to `stdout'
ATM.c:(.text+0x135): undefined reference to `fwrite'
ATM.c:(.text+0x13c): undefined reference to `stdin'
ATM.c:(.text+0x14f): undefined reference to `fscanf'
ATM.c:(.text+0x165): undefined reference to `stdout'
ATM.c:(.text+0x179): undefined reference to `fwrite'
ATM.c:(.text+0x18a): undefined reference to `stdout'
ATM.c:(.text+0x19e): undefined reference to `fwrite'
ATM.o: In function `get_acct_num':
ATM.c:(.text+0x1d2): undefined reference to `stdout'
ATM.c:(.text+0x1e6): undefined reference to `fwrite'
ATM.c:(.text+0x1ed): undefined reference to `stdin'
ATM.c:(.text+0x200): undefined reference to `fscanf'
ATM.c:(.text+0x216): undefined reference to `stdout'
ATM.c:(.text+0x22a): undefined reference to `fwrite'
ATM.o: In function `get_money_num':
ATM.c:(.text+0x254): undefined reference to `stdout'
ATM.c:(.text+0x268): undefined reference to `fwrite'
ATM.c:(.text+0x26f): undefined reference to `stdin'
ATM.c:(.text+0x282): undefined reference to `fscanf'
 
Old 08-20-2009, 11:13 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
If stdio.h was not included, the compiler would bomb. You have linker errors.

Are you mixing C and C++ here? How are you compiling your modules? I'm guessing that the linker isn't finding libc. It must be present in your system or else an awful lot of user programs just wouldn't run.

Take a look at /etc/ld.conf and see what it has in it. libc should be in /lib.
 
Old 08-20-2009, 11:14 PM   #3
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Code:
gcc ATM.o -o ATM
 
Old 08-20-2009, 11:54 PM   #4
Jetfire29
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jiml8 View Post
If stdio.h was not included, the compiler would bomb. You have linker errors.

Are you mixing C and C++ here? How are you compiling your modules? I'm guessing that the linker isn't finding libc. It must be present in your system or else an awful lot of user programs just wouldn't run.

Take a look at /etc/ld.conf and see what it has in it. libc should be in /lib.
It's just a simple C program.

Yeah, I found libc, so what do I do with it? I'm not really good with the commands in terminal, so I don't know how to link files, or is that what I do? Also, how can I run it to test it if it compiles and such? Just type in the name?

Thanks so much.
 
Old 08-21-2009, 07:38 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Jetfire29 View Post
I don't know how to link files
I think the command Valery posted should be the correct way to link your program.

It may seem counter intuitive to use the same program to link that you used to compile, but that is how it works.

If you use the linker directly, you need to supply a lot more information, such as the location of libc. If you use that gcc command it will create (and invoke) an ld command that provides good defaults for a lot of information including libc.

Quote:
Also, how can I run it to test it if it compiles and such? Just type in the name?
Probably you don't have . in your path, so to run it you need ./name rather than just name

Last edited by johnsfine; 08-21-2009 at 07:39 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Including header files and source files for classes Feenix Programming 8 09-28-2005 10:53 AM
VMware & "directory of C header files" pacranch Amigo 12 05-14-2005 03:39 PM
gcc header files and cpp files? EchO Linux - Software 3 03-01-2005 01:14 AM
rpm -Uvh does not work with header & rpm files in /var/spool/up2date jd_no7 Linux - Software 1 05-17-2004 05:24 PM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:32 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