makefile - Linking step doesn't get object files from correct location -


i've written makefile links in few ffmpeg libraries , compiles basic hello world piece of code. want object files , executable go ./bin folder. use vpath include ./bin directory when dealing .o files. when compile after make clean, first time, during link step, tries .o file current directory, instead of path specified in vpath. second time though, there isn't problem.

i create bin directory folder in make file , may have it, however, don't see problem in compile step when generates .o files.

here make file:

ifeq (0, ${makelevel}) cur-dir := $(shell pwd) whoami  := $(shell whoami ) host-type := $(shell arch ) endif  cc=gcc cflags :=-c -wall -pthread -o $(bindir)/$@ ldflags :=-lpthread ffmpeg := ${cur-dir}/ffmpeg fflibs := -lavcodec -lavdevice -lavformat fflibpath := -l${ffmpeg}/libavcodec -l${ffmpeg}/libavdevice -l${ffmpeg}/libavformat sources := pthreadex.c objects := $(sources:.c=.o) bindir := ./bin executable := micgrabber incfile := -i${ffmpeg}/libavformat \            -i${ffmpeg}/libavcodec \            -i${ffmpeg}/libavdevice  vpath %.o $(bindir) all: directories $(objects) $(executable)  $(executable): $(objects)     $(cc) $(ldflags) $(fflibpath) $(fflibs) $< -o $(bindir)/$@  pthreadex.o: pthreadex.c     $(cc) $(cflags) $< -o $(bindir)/$@  clean:     rm -rf *.o     rm -rf $(bindir)  .phony: directories  directories: ${bindir}  ${bindir}:      mkdir -p ${bindir} 

i'm not sure why, on first attempt compile, looks in wrong place .o file.

here output ( including gcc command generated ) after running make first time.

[root@kartikcentosvm sf_audioproj]# make clean rm -rf *.o rm -rf ./bin [root@kartikcentosvm sf_audioproj]# make mkdir -p ./bin gcc -c -wall -pthread -o / pthreadex.c -o ./bin/pthreadex.o gcc -lpthread -l/media/sf_audioproj/ffmpeg/libavcodec -l/media/sf_audioproj/ffmpeg/libavdevice  -l/media/sf_audioproj/ffmpeg/libavformat -lavcodec -lavdevice -lavformat  pthreadex.o -o ./bin/micgrabber gcc: pthreadex.o: no such file or directory make: *** [micgrabber] error 1 

at point, bin directory has been created , compile step succeeded , there pthreadex.o file in bin folder. link step fails. run make again , now.

[root@kartikcentosvm sf_audioproj]# make gcc -lpthread -l/media/sf_audioproj/ffmpeg/libavcodec -l/media/sf_audioproj/ffmpeg /libavdevice -l/media/sf_audioproj/ffmpeg/libavformat -lavcodec -lavdevice -lavformat  ./bin/pthreadex.o -o ./bin/micgrabber 

the compile step isn't performed because object file exists , current, , time link step sources object file correct location.

can tell me wrong in makefile ?

i don't know entire problem, rule:

pthreadex.o: pthreadex.c         $(cc) $(cflags) $< -o $(bindir)/$@ 

is lying make. says $(cc) command takes pthreadex.c, should subject vpath lookup (but seems not necessary in case) , produces pthreadex.o in current directory (targets not automatically assumed going vpath location). however, actual command puts pthreadex.o in $(bindir).

this rule might better:

$(bindir)/pthreadex.o: pthreadex.c         $(cc) $(cflags) $< -o $@ 

honestly, i'm adrian in comment above - dispense vpath bit , make rules explicit. vpath-ing can cause sorts of general wonkiness that's hard debug.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -