I know this error has been beaten to death, but I cannot seem to get it to work. I have linked my makefile below:
all: gensine info cs229towav
encode.o: encode.h encode.c
gcc -c encode.c
write.o: write.c write.h
gcc -c write.c
gensine.o: encode.c gensine.h gensine.c helper.c write.c
gcc -c gensine.c -lm
helper.o: helper.c helper.h
gcc -c helper.c
read.o: read.h read.c
gcc -c read.c
info.o:read.c info.h info.c decode.c
gcc -c info.c
decode.o: decode.c decode.h helper.c
gcc -c decode.c
cs229towav.o: write.c read.c cs229towav.c cs229towav.h helper.c decode.c encode.c
gcc -c cs229towav.c -lm
gensine: encode.o gensine.o write.o helper.o
gcc -o gensine encode.o gensine.o write.o helper.o -lm
info: read.o info.o decode.o helper.o
gcc read.o info.o decode.o helper.o
cs229towav: write.o read.o cs229towav.o decode.o encode.o helper.o
gcc -o write.o read.o cs229towav.o decode.o encode.o helper.o -lm
Clean:
rm -rf *o gensine info cs229towav
When I run a command such as “make gensine” I am returned with the following result:
>cc gensine.c -o gensine
/tmp/ccojm09X.o: In function `encodeCsFormat':
gensine.c:(.text+0x4b1): undefined reference to `sin'
/tmp/ccojm09X.o: In function `encodeWavFormat':
gensine.c:(.text+0xa39): undefined reference to `sin'
collect2: error: ld returned 1 exit status
After reading this is says undefined reference to sin, which is with the math library. Those functions listed are in the “encode.c” file which are included in the “gensine.c” file.
The command in the makefile:
does not match the command you printed at the end:
Notice also that there is no
-lmNote that
makeknows how to make object files so you don’t need most of the makefile. Try this (remember to indent with TABs):Edit:
Boddie, note that your confusion arose because you thought the makefile was a script – ie. that you were running your script named
makewhen you typedmake gensine. In factmakeis a command likegccsomewhere else in the filesystem (on Linux etc, typewhich maketo see where it is). Themakecommand expects to find an input file containing build rules calledmakefileorMakefilein the current directory. If it doesn’t find that file it uses some built-in rules instead – hence thecc gensine.c -o gensinewhich is nowhere in your makefile. If you want to, you can tellmakethe name of the makefile (so that it doesn’t use the default names) with the-fswitch, as @DanielFischer described in the comments.