The error is:
Somehow the linking is not done, and whatever I define isn't available.Originally Posted by make
Is there some separate flag necessary for specifying source and object files together ?
The error is:
Somehow the linking is not done, and whatever I define isn't available.Originally Posted by make
Is there some separate flag necessary for specifying source and object files together ?
Not as far as I know. gcc/g++ should be smart enough to figure out a .o is an object file, and doesn't compile it, just links it.
It would help immensely if you posted your make file, though perhaps you can sort out the make file issues once you see the problem. These two lines (immediately above the red lines) are what's causing the error:
For some reason you're calling g++ again, this time on the .o file and it's .cpp file, but still using the -c option, so it's strictly compilation, no linking.g++ input.o input_test.cpp -std=c++0x -o input_test.o -c
...
g++ argument.o argument_test.cpp -std=c++0x -o argument_test.o -c
I misread a bit. I see now that the above use "input.o" and "input_test.cpp". You don't use a .o file if you're strictly compiling. Moving them to the linking line would help:
You don't have input.o anywhere in that list, so it can't find input::input(char **). You also don't have argument.o in there.g++ input_test.o argument_test.o test_main.cpp -std=c++0x -o test
That is the problem.For some reason you're calling g++ again, this time on the .o file and it's .cpp file, but still using the -c option, so it's strictly compilation, no linking.
I want to make it somewhat hierarchical, but these object files ... need to be "fused" by force for that.
It works fine when all the files are given to the compiler at the same time.
The makefile is.... in a raw form:
Code:test: input_test argument_test test_main.cpp g++ input_test.o argument_test.o test_main.cpp -std=c++0x -o test input_test : input input_test.cpp g++ input.o input_test.cpp -std=c++0x -o input_test.o -c argument_test : argument argument_test.cpp g++ argument.o argument_test.cpp -std=c++0x -o argument_test.o -c input: input.cpp input.h g++ input.cpp -std=c++0x -o input.o -c argument: argument.cpp argument.h g++ argument.cpp -std=c++0x -o argument.o -c
My basic make file for a single directory with a single target executable looks something like this (change extensions and flags as needed for C++):
Code:CC:= gcc CFLAGS := -c -Wall # Sources are all .c files in this dir SRCS := $(wildcard *.c) # Object files are everything in $SRCS, with the .c replaced by a .o OBJS := $(patsubst %.c, %.o, $(SRCS)) TARGET := executable_name # Default target makes the executable, so you just type 'make' at the command line default : $(TARGET) # Make every .o file require it's corresponding .c file # For each such file, call the compiler with the specified flags # Use the requisite ($<) as input (the .c file) # Use the target name ($@) as the output file name (the .o file) %.o : %.c $(CC) $(CFLAGS) $< -o $@ # Make the executable require all the object files # Use all the requisites ($^), as input files (the .o files) for the linker # Output file is $TARGET, which is executable_name $(TARGET) : $(OBJS) $(CC) $(LDFLAGS) $^ -o $(TARGET) # Simple clean up target clean : rm -f $(OBJS) $(TARGET)