I know similar questions have been asked before, but I've read a lot of the previous questions and the errors in those cases don't solve the issue I have.
The issue I am having is that, when I call make
, the final linking step errors out with this output:
g++ -Wall -Werror -std=c++11 -c -o /home/vjon/Code/Projects/otto-challenge/build/waypoint.o /home/vjon/Code/Projects/otto-challenge/src/waypoint.cpp
g++ -Wall -Werror -std=c++11 -c -o /home/vjon/Code/Projects/otto-challenge/build/otto.o /home/vjon/Code/Projects/otto-challenge/src/otto.cpp
g++ -Wall -Werror -std=c++11 -c -o /home/vjon/Code/Projects/otto-challenge/build/main.o /home/vjon/Code/Projects/otto-challenge/src/main.cpp
g++ -Wall -Werror -std=c++11 -o /home/vjon/Code/Projects/otto-challenge/build/a.out /home/vjon/Code/Projects/otto-challenge/build/waypoint.o /home/vjon/Code/Projects/otto-challenge/build/otto.o /home/vjon/Code/Projects/otto-challenge/build/main.o
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target '/home/vjon/Code/Projects/otto-challenge/build/a.out' failed
make: *** [/home/vjon/Code/Projects/otto-challenge/build/a.out] Error 1
This is despite int main()
being defined in "main.cpp". For reference, here's the makefile I've written:
# Copyright (c) 2016-present, Jonathan Lee
# All rights reserved.
#
# This source code is licensed under the ISC license found in the LICENSE
# file in the root directory of this source tree.
PROJECT_DIR := $(shell pwd)
BUILD_DIR := $(PROJECT_DIR)/build
INCLUDE_DIR := $(PROJECT_DIR)/include
SOURCE_DIR := $(PROJECT_DIR)/src
CXXFLAGS = -Wall -Werror -std=c++11
DEPS = waypoint.h otto.h
HEADERS = $(patsubst %,$(INCLUDE_DIR)/%,$(DEPS))
OBJS = waypoint.o otto.o main.o
OBJECTS = $(patsubst %,$(BUILD_DIR)/%,$(OBJS))
.PHONY: all clean
all: $(BUILD_DIR)/a.out
$(BUILD_DIR)/a.out: $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(HEADERS)
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
@rm -rf $(BUILD_DIR)/*
In the interest of full disclosure, this project is for a coding challenge I have been given (hence why I have not included the contents of the headers/source files I have written). However, since the purpose of the challenge is to test my algorithms/code skills and not my GNU make skills, I figured it would be okay to ask for help in this one area.
Worst case, I'll rewrite it in Python to get around the need for make, but I would prefer to figure out what I've gotten wrong here instead of taking the "easy" way out.
Thanks in advance for any help!
Aucun commentaire:
Enregistrer un commentaire