using c to link object files

I know I should just google this.. but my computer is getting hot.  I made a file with this function I find myself resuing called "print_interval.c"  You can see all it has is necessary include files and the function.  Here is my Makefile:

kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ cat Makefile
DEBUG_FLAG = -g -O0

dirty_demog : dirty_demog.o
      gcc ${DEBUG_FLAG} -o dirty_demog -lrt dirty_demog.o

dirty_demog.o :
      gcc -c dirty_demog.c

simple_read : simple_read.o
      gcc ${DEBUG_FLAG} -o print_interval -o simple_read -lrt simple_read.o

simple_read.o :
      gcc -c simple_read.c

print_interval.o :
      gcc -c print_interval.c
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $


I thought this would work.. but it doesn't.  I tried caling  the function "print_interval" from the source file "simple_read.c"  and this is what happened when I made:

kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ make simple_read
gcc -c simple_read.c
simple_read.c: In function 'main':
simple_read.c:37: warning: unknown conversion type character 0x20 in format
simple_read.c:53: warning: format '%d' expects type 'int', but argument 3 has type 'long long int'
simple_read.c:59: warning: format not a string literal and no format arguments
simple_read.c:80: warning: format not a string literal and no format arguments
simple_read.c:85: warning: format '%d' expects type 'int', but argument 2 has type 'long long int'
gcc -g -O0 -o print_interval -o simple_read -lrt simple_read.o
simple_read.o: In function `main':
simple_read.c:(.text+0x3ee): undefined reference to `print_interval'
collect2: ld returned 1 exit status
make: *** [simple_read] Error 1
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $

kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ uname -a
Linux kayve-gentoo 2.6.32-gentoo-r7 #1 SMP Fri Apr 9 03:09:09 PDT 2010 i686 Intel(R) Core(TM)2 Duo CPU T6400 @ 2.00GHz GenuineIntel GNU/Linux
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $

I was hoping to reuse this file "print_interval.c" as you can see from the Makefile, I have other files.. the other make directive I just have the code in there.  I was about the copy and paste, and then I was like telling myself.. d00d.  learn to reuse code finally after decades of being a buttinsky.  


kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ cat print_interval.c 
#include <stdio.h>
#include <time.h>
#include <sys/time.h>


int print_interval(struct timespec* start, struct timespec* end) {
  long long interval,ninterval;
 
  interval = ((int)(end->tv_sec)-(int)(start->tv_sec));
  ninterval = ((int)(end->tv_nsec)-(int)(start->tv_nsec));
  ninterval += BILLION*interval;
  ninterval = ninterval/1000;
  printf(" %d usec",ninterval);
}

kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $

Open in new window

kayveyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kayveyAuthor Commented:
OK. I made a boo boo.  Here is a better Makefile
DEBUG_FLAG = -g -O0

dirty_demog : dirty_demog.o
        gcc ${DEBUG_FLAG} -o dirty_demog -lrt dirty_demog.o 

dirty_demog.o :
        gcc -c dirty_demog.c

simple_read : simple_read.o
        gcc ${DEBUG_FLAG} print_interval.o -o simple_read -lrt simple_read.o 

simple_read.o :
        gcc -c simple_read.c

print_interval.o :
        gcc -c print_interval.c
~                                                                               
~                                                                               
~

Open in new window

0
kayveyAuthor Commented:
Here is what the make looked like:

kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ make simple_read
gcc -g -O0 print_interval.o -o simple_read -lrt simple_read.o
gcc: print_interval.o: No such file or directory
make: *** [simple_read] Error 1
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $
0
kayveyAuthor Commented:
Woops.  This might turn out to be an eeeeassy question!


DEBUG_FLAG = -g -O0

dirty_demog : dirty_demog.o
        gcc ${DEBUG_FLAG} -o dirty_demog -lrt dirty_demog.o 

dirty_demog.o :
        gcc -c dirty_demog.c

simple_read : simple_read.o print_interval.o
        gcc ${DEBUG_FLAG} print_interval.o -o simple_read -lrt simple_read.o 

simple_read.o :
        gcc -c simple_read.c

print_interval.o :
        gcc -c print_interval.c
~                                                                               
~

Open in new window

0
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

kayveyAuthor Commented:
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ make simple_read
gcc -c print_interval.c
print_interval.c: In function 'print_interval':
print_interval.c:11: error: 'BILLION' undeclared (first use in this function)
print_interval.c:11: error: (Each undeclared identifier is reported only once
print_interval.c:11: error: for each function it appears in.)
print_interval.c:13: warning: format '%d' expects type 'int', but argument 2 has type 'long long int'
make: *** [print_interval.o] Error 1
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $
0
kayveyAuthor Commented:
Easy questions are good because they make up for the impossible ones I ask.  
0
kayveyAuthor Commented:
Easy question

e are 0 lines in the file
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $ ./simple_read uniprot_sprot.dat
the "uniprot_sprot.dat" file is 2008143039
 bytes.
there are 0 lines in the file
it took  2815586 usec to run.
kayve@kayve-gentoo ~/src/thesis/CSc899/gentoo $
0
phoffricCommented:
I added the following #define to print_interval.c and now it compiles. As far as your other errors I don't see the simple_read.c file in this thread.
#define BILLION (1000000000)

int print_interval(struct timespec* start, struct timespec* end) {
...

Open in new window

0
phoffricCommented:
>> print_interval.c:13: warning: format '%d' expects type 'int', but argument 2 has type 'long long int'
To remove this warning, use %lld instead of %d

See    http://en.wikipedia.org/wiki/Printf
"Length can be omitted or be any of:"
"ll  -  For integer types, causes printf to expect a long long sized integer argument"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.