0

I am getting the following output from my makefile. My main goal is to compile everything in a directory. I expect to have many more cpp files in future. Any tips or advice is greatly appreciated!

Output:

g++ `pkg-config --libs --cflags opencv libexif` main.cpp -o main.o
g++ `pkg-config --libs --cflags opencv libexif` Image.cpp -o Image.o
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)
make: *** [Image.o] Error 1

Current list of files: main.cpp, Image.h, Image.cpp

Here's the makefile:

CC=g++
CFLAGS= `pkg-config --libs --cflags opencv libexif`
LDFLAGS= `pkg-config --libs --cflags opencv libexif`
SOURCES=main.cpp Image.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=CvHelloWorld

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@

clean:
    rm *.o
Batman
  • 541
  • 4
  • 25
user1035839
  • 153
  • 3
  • 13

1 Answers1

0

As suggested by @5gon12eder, you should use '-c'.

.cpp.o:
    $(CC) -c $(CFLAGS) -o $@ $<

Debug is easier if you interpret pkg-config results earlier:

CFLAGS  := $(shell pkg-config --cflags opencv libexif)
LDFLAGS := $(shell pkg-config --libs opencv libexif)
SOURCES := $(wildcard *.cpp)

[...]

.PHONY: clean
Community
  • 1
  • 1
levif
  • 2,156
  • 16
  • 14