I have this structure for my project:
root
|____Makefile
|
|___src
| |____*.cpp
|
|___includes
| |___*.h
|
|___obj
|___tmp
|___bin
The problem is that when i try to make i got this error:
g++ -std=c++11 obj/book.o -o bin/main
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My main.cpp is inside src than i have a file .h where i declare a struct and some function and a .cpp where i define everything. In the main and in the cpp i do
#include "../includes/myfile.h"
How i can compile and fix this problem? Here is my makefile:
CXX = g++
CXXFLAGS = -std=c++11 -I..
LDFLAGS = -std=c++11
EXECUTABLE= bin/main
SOURCES = $(wildcard src/*.cpp)
HEADERS = $(wildcard includes/*.h)
OBJECTS = $(patsubst src/%.cpp, obj/%.o, $(SOURCES))
BASE = $(USER)
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CXX) $(LDFLAGS) $< -o $@
obj/%.o: src/%.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
clean:
rm $(OBJECTS)
rmproper:
rm $(OBJECTS) $(EXECUTABLE)
pdf:
a2ps Readme.txt makefile $(HEADERS) $(SOURCES) -o /tmp/out.ps
ps2pdf /tmp/out.ps $(BASE).pdf
zip:
zip $(BASE).zip Readme.txt makefile $(HEADERS) $(SOURCES)