c - Building object files that depends on other object files -


edits: including link makefile

i have main program calls bunch of functions defined in other source files. not problem because using cc -c functionsource.c functionheader.h , generating object files before compiling main program cc main.c func1.o func2.o .... -o test.o

i having problems when 1 of functions depends on function. example: main program calls shuffle function defined in it's own source file , shuffle function calls swap function in turn defined in it's own source file.

when try generate shuffle.o file main program using cc -c shuffle.o undefined reference swap error.

when try cc shuffle.c swap.o undefined reference main error.

here makefile

how go fixing this? found problem. had swap function declared inside insertionsort.h , shuffle.h no implementations.

have man page: '-c' makes compiler generating object files (not trying link).

do following:

cc -c insertionsort.c     # => gives insertionsort.o cc -c -c functionsource.c # => gives functionsource.o cc insertionsort.o functionsource.o ...and-so-on... main.c -o test  

it's not necessary specify header files - doesn't help.

btw: if have mor 1 implementation file, rather useful

  • (a) learn make
  • (b) stick convention object files , programs should named th sources.

e.g:

foo.c => foo.o bar.c => bar 

etc - picture.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -