Issues with defining output objects

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Issues with defining output objects

zxuiji
I'm still new to makefiles so could someone help me understand the below correctly please. Here's the snippet of my makefile:

SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:%.c=%.o)
...
$(.DEFAULT_GOAL): $(.DEFAULT_GOAL)/$(OBJECTS)
	$(CC) $(.DEFAULT_GOAL)/$(OBJECTS) -o $(OUT)

$(.DEFAULT_GOAL)/%.o: %.c
	$(CC) $(TAR_LIBS) $(TAR_INCS) $(TAR_OBJF) -c $< -o $@
And this is the output I'm getting after the 1st file:

/MinGW64/bin/mingw32-make.exe (in directory: E:\PortableApps\Codit\coditui)
/MinGW64/mingw/bin/mingw32-gcc.exe win32_dbg/search.o main.o inject.o -o ./../bin/codit_win32_dbg.exe
main.o:search.c:(.text+0x0): multiple definition of `sysOpenProc'
win32_dbg/search.o:search.c:(.text+0x0): first defined here
main.o:search.c:(.text+0x11b): multiple definition of `sysShutProc'
win32_dbg/search.o:search.c:(.text+0x11b): first defined here
main.o:search.c:(.text+0x13d): multiple definition of `uquery'
win32_dbg/search.o:search.c:(.text+0x13d): first defined here
main.o:search.c:(.text+0x156): multiple definition of `iquery'
win32_dbg/search.o:search.c:(.text+0x156): first defined here
main.o:search.c:(.text+0x16f): multiple definition of `fquery'
win32_dbg/search.o:search.c:(.text+0x16f): first defined here
main.o:search.c:(.text+0x188): multiple definition of `squery'
win32_dbg/search.o:search.c:(.text+0x188): first defined here
main.o:search.c:(.bss+0x0): multiple definition of `procId'
win32_dbg/search.o:search.c:(.bss+0x0): first defined here
main.o:search.c:(.bss+0x4): multiple definition of `procHandle'
win32_dbg/search.o:search.c:(.bss+0x4): first defined here
main.o:search.c:(.bss+0x8): multiple definition of `procMemAddr'
win32_dbg/search.o:search.c:(.bss+0x8): first defined here
main.o:search.c:(.bss+0xc): multiple definition of `procMemSize'
win32_dbg/search.o:search.c:(.bss+0xc): first defined here
inject.o:search.c:(.text+0x0): multiple definition of `sysOpenProc'
win32_dbg/search.o:search.c:(.text+0x0): first defined here
inject.o:search.c:(.text+0x11b): multiple definition of `sysShutProc'
win32_dbg/search.o:search.c:(.text+0x11b): first defined here
inject.o:search.c:(.text+0x13d): multiple definition of `uquery'
win32_dbg/search.o:search.c:(.text+0x13d): first defined here
inject.o:search.c:(.text+0x156): multiple definition of `iquery'
win32_dbg/search.o:search.c:(.text+0x156): first defined here
inject.o:search.c:(.text+0x16f): multiple definition of `fquery'
win32_dbg/search.o:search.c:(.text+0x16f): first defined here
inject.o:search.c:(.text+0x188): multiple definition of `squery'
win32_dbg/search.o:search.c:(.text+0x188): first defined here
inject.o:search.c:(.bss+0x0): multiple definition of `procId'
win32_dbg/search.o:search.c:(.bss+0x0): first defined here
inject.o:search.c:(.bss+0x4): multiple definition of `procHandle'
win32_dbg/search.o:search.c:(.bss+0x4): first defined here
inject.o:search.c:(.bss+0x8): multiple definition of `procMemAddr'
win32_dbg/search.o:search.c:(.bss+0x8): first defined here
inject.o:search.c:(.bss+0xc): multiple definition of `procMemSize'
win32_dbg/search.o:search.c:(.bss+0xc): first defined here
win32_dbg/search.o:search.c:(.text+0x7): undefined reference to `coditRef'
win32_dbg/search.o:search.c:(.text+0xf): undefined reference to `coditPtr'
main.o:search.c:(.text+0x7): undefined reference to `coditRef'
main.o:search.c:(.text+0xf): undefined reference to `coditPtr'
inject.o:search.c:(.text+0x7): undefined reference to `coditRef'
inject.o:search.c:(.text+0xf): undefined reference to `coditPtr'
e:/mingw64/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
makefile:19: recipe for target 'win32_dbg' failed
mingw32-make.exe: *** [win32_dbg] Error 1
Compilation failed.
Reply | Threaded
Open this post in threaded view
|

Re: Issues with defining output objects

zxuiji
Never mind, I figured out how to sort it:

...
OBJS=$(patsubst %.c, ${CURDIR}/../objs/$(.DEFAULT_GOAL)/%.o, $(SOURCES))
OUT=${CURDIR}/../../bin/codit_$(.DEFAULT_GOAL)$(EXE)

$(.DEFAULT_GOAL): $(OBJS)
	$(CC) $(LIBS) $(OBJS) -o $(OUT)

$(OBJS): ${CURDIR}/../objs/$(.DEFAULT_GOAL)/%.o : %.c
	$(CC) -v $(LIBS) $(INCS) $(CFLAGS) -c $< -o $@
...
I shifted the OBJS variable to after the forced definition of .DEFAULT_GOAL to ensure nothing went to undesired locations.