P
prasadjoshi124
Hi All,
I am trying to write a make file with the following specifications.
[Prasad@rsharma dir_make]$ pwd
/home/Prasad/programs/c/lsp/dir_make
[Prasad@rsharma dir_make]$ ls
add include main.c Makefile sub
Now, here main.c uses a function present in add/add.c and sub/sub.c.
I have written this makefile
[Prasad@rsharma dir_make]$ cat Makefile
SUB_DIRS := add sub
all:
@for d in $(SUB_DIRS) ; do \
( \
cd $$d ; \
make ; \
) \
done
OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
echo $(OBJ_FILES)
gcc main.c -o main -I $$PWD/include $(OBJ_FILES)
clean:
OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
echo $(OBJ_FILES)
rm $(OBJ_FILES)
But, it does not seem to work properly. I am getting following error
==>
[Prasad@rsharma dir_make]$ make
make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/add'
make[1]: `add.o' is up to date.
make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/add'
make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/sub'
make[1]: `sub.o' is up to date.
make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/sub'
OBJ_FILES=
echo
gcc main.c -o main -I $PWD/include
/tmp/ccmR5Xy4.o: In function `main':main.c.text+0x21): undefined
reference to `add'
:main.c.text+0x45): undefined reference to `sub'
collect2: ld returned 1 exit status
make: *** [all] Error 1
It seems that OBJ_FILES variable is not getting set properly.
Please help.
Thanks and regards,
Prasad.
I am trying to write a make file with the following specifications.
[Prasad@rsharma dir_make]$ pwd
/home/Prasad/programs/c/lsp/dir_make
[Prasad@rsharma dir_make]$ ls
add include main.c Makefile sub
Now, here main.c uses a function present in add/add.c and sub/sub.c.
I have written this makefile
[Prasad@rsharma dir_make]$ cat Makefile
SUB_DIRS := add sub
all:
@for d in $(SUB_DIRS) ; do \
( \
cd $$d ; \
make ; \
) \
done
OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
echo $(OBJ_FILES)
gcc main.c -o main -I $$PWD/include $(OBJ_FILES)
clean:
OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
echo $(OBJ_FILES)
rm $(OBJ_FILES)
But, it does not seem to work properly. I am getting following error
==>
[Prasad@rsharma dir_make]$ make
make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/add'
make[1]: `add.o' is up to date.
make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/add'
make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/sub'
make[1]: `sub.o' is up to date.
make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/sub'
OBJ_FILES=
echo
gcc main.c -o main -I $PWD/include
/tmp/ccmR5Xy4.o: In function `main':main.c.text+0x21): undefined
reference to `add'
:main.c.text+0x45): undefined reference to `sub'
collect2: ld returned 1 exit status
make: *** [all] Error 1
It seems that OBJ_FILES variable is not getting set properly.
Please help.
Thanks and regards,
Prasad.