The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-04-2008
marcintom's Avatar
marcintom marcintom is offline
Registered User
 

Join Date: Dec 2007
Posts: 7
Question Makefile very simple question.

Hi
I tried many times and I dont know what the he... is going on.

Problem:
I hava in /home/marcin/c1_menu/
this file:
menu_item_data.c

I want to compile this file.
so I tried something like this
Code:
CC=gcc
LIBS=-lmenu -lncurses
RM=rm

BINS=menu_item_data

%: %.o
    ${CC} -o $@ $< ${LIBS} 

%.o: %.c
    ${CC} -o $@ -c $< 

.PHONY: all clean


all: $(BINS)
    echo "Jeśli nie widzisz błędów to wszystko OKi"

clean:
    ${RM} -f ${BINS}
when I tried make in /home/marcin/c1_menu/.
I get somethig like this

Code:
$ make
gcc     menu_item_data.c   -o menu_item_data
menu_item_data.c: In function 'main':
menu_item_data.c:29: warning: incompatible implicit declaration of built-in function 'calloc'
/tmp/ccsA63dp.o: In function `main':
menu_item_data.c:(.text+0x14): undefined reference to `initscr'
(......)
menu_item_data.c:(.text+0x215): undefined reference to `endwin'
collect2: ld returned 1 exit status
make: *** [menu_item_data] Błąd 1
but when I try manualy everythign is ok

Code:
[marcin@zet c1_menu(0)]$ ls 
makefile  menu_item_data.c
[marcin@zet c1_menu(0)]$ vim m  
makefile          menu_item_data.c  
[marcin@zet c1_menu(0)]$ vim makefile  
[marcin@zet c1_menu(0)]$ gcc -o menu_item_data.o -c menu_item_data.c 
menu_item_data.c: In function 'main':
menu_item_data.c:29: warning: incompatible implicit declaration of built-in function 'calloc'
[marcin@zet c1_menu(0)]$ gcc -o menu_item_data menu_item_data.o -lmenu -lncurses
[marcin@zet c1_menu(0)]$ ls
makefile  menu_item_data  menu_item_data.c  menu_item_data.o
[marcin@zet c1_menu(0)]$
Why there are no LIBS ?
Code:
[marcin@zet c1_menu(0)]$ make -f makefile -n
gcc     menu_item_data.c   -o menu_item_data
echo "Jeśli nie widzisz błędów to wszystko OKi"

My target is compiling many files in one dir.
for example
if I had
x1.c x2.c ..... x100.c

and I have
BINS= x1.c x2.c .... x100.c
or something like a loop in Makefile


Please help me I can't get clear WORKING example from enybody.
Reply With Quote
Forum Sponsor