Thread: linking .o from another directory with makefile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Where do you call make from? File names have to be relative to the makefiles position.
    Devoted my life to programming...

  2. #2
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    Quote Originally Posted by GReaper View Post
    Where do you call make from? File names have to be relative to the makefiles position.
    I'm calling make from the getanumber dir.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by loaded View Post
    I'm calling make from the getanumber dir.
    So, obviously, getch.o( and everything else not in that directory ), need to be prefixed with the relative or absolute path, eg:
    ../mainop/getch.o
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    Quote Originally Posted by GReaper View Post
    So, obviously, getch.o( and everything else not in that directory ), need to be prefixed with the relative or absolute path, eg:
    ../mainop/getch.o
    Sorry, I didn't understand. You mean I need to include all the .c? but I just need the .o of getch.c since the getanumber.c only use two functions from this source. Hum, the header calc.h declares the functions of getch.c and the others functions that are inside mainop directory. Still, I'd like to compile getch only.

    I tried some variations but it didn't work. gcc -I ../mainop -o maingetanumber getanumber.o -include ../mainop/getch.o -Wall -pedantic

    Code:
     
      maingetanumber : getanumber.o getch.o
        gcc -include ../mainop/getch.o -o maingetanumber getanumber.o -Wall -pedantic
    
    getanumber.o : getanumber.c
        gcc -I ../headers -c getanumber.c
    Code:
     
      maingetanumber : getanumber.o getch.o
         gcc -I ../mainop -o maingetanumber getanumber.o ../mainop/getch.o -Wall -pedantic
     
     getanumber.o : getanumber.c
         gcc -I ../headers -c getanumber.c
    Code:
    gcc -I ../mainop -o maingetanumber getanumber.o -include ../mainop/getch.o -Wall -pedantic

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking to libraries in the current directory
    By Thiago in forum C Programming
    Replies: 7
    Last Post: 06-09-2010, 07:11 PM
  2. Replies: 2
    Last Post: 08-11-2009, 06:45 AM
  3. Multi-directory Makefile
    By reelbigtim in forum C Programming
    Replies: 3
    Last Post: 10-29-2007, 10:16 AM
  4. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  5. help: makefile: directory rules
    By paulur in forum C Programming
    Replies: 5
    Last Post: 03-19-2006, 11:43 PM