mardi 21 juin 2016

MakeFile compiles only one file


I started working on a small project to implement a todo app in C++.

I wrote a Makefile to compile my C++ files but , the Makefile Only compiles main.cc and nothing else.

Here is my MakeFile

#MakeFile for Building the ToDoList App

# Compile CXX Files
CXX := g++-4.9
CXXFLAGS := -std=c++11
CXXFILES := $(wildcard src/*.cc src/lexer/*.cc)
CXXOBJECTS := $(CXXFILES:.cc=.o)
CXXHEADERS := $(wildcard *.h)

# Link all Object Files
LD := ld
LDFLAGS :=

# Declare Clean and Run as Phony Targets
.PHONY: clean run

# The Final Product will be the To-Do APP
all: TedO.app

# Compile the ToDO APP
TedO.app: $(CXXOBJECTS)
            $(LD) $(LDFLAGS) -o build/$@ $^

# Run the APP from the Build Folder
run: TedO.app
    ./build/$^

# Compile the CC files into Object files and place it into the same directory.
%.o: %.cc
    $(CXX) $(CXXFLAGS) -o $@ $< 

# Clean all the Objects
clean: $(CXXOBJECTS)
        rm $^

Here is my Directory Structure

.
├── Makefile
├── Makefile.swp
├── build
│   ├── tedo
│   └── tedo.txt
├── doc
├── src
│   ├── lexer
│   │   ├── lexer.cc
│   │   └── lexer.h
│   └── main.cc
└── tree.txt

4 directories, 8 files

Here is my Output from the Console when running Make

g++-4.9 -std=c++11 -o src/main.o src/main.cc
Undefined symbols for architecture x86_64:
  "lexer::lexer()", referenced from:
      _main in ccmWqgIU.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [src/main.o] Error 1

Aucun commentaire:

Enregistrer un commentaire