I have problems with my Makefile.
I am trying to create a program from 2 files - main.cpp, which contains the main function, and modules.c, which contains the definitions of the functions called in main (). modules.c contain only function definitions, there is no main function.
My makefile looks like this:
CC := gcc CXX := g++ LINK := g++ -Wall CFLAGS := -g CXXFLAGS := -g TARGET = program $(TARGET): modules.o main.o $(LINK) -o $@ $< -lpcap clean: rm *.o $(TARGET) modules.o: $(CC) $(CFLAGS) -c modules.c -o $@ $< main.o: $(CXX) $(CXXFLAGS) -c main.cpp -o $@ $<
I included "modules.h", which contains all the function declarations, in my main.cpp. The CFLAGS and CXXFLAGS variables point to the correct paths containing
When I try to do this with this makefile, I get an error
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../lib64/crt1.o: In the '_start' function:
(.text + 0x20): undefined reference to 'main'
If I switch the order of modules.o and main.o in my $ (TARGET) line, I get errors that say "undefined reference to" the functions that I defined in modules.c, basically. castes.
I do not know what is wrong.
Thanks.
Regards, Rayne
source share