Reputation: 685
My Makefile:
CXX = g++
CXXFLAGS = -g -Wall -std=c++14
LDFLAGS = -lboost_system -lcrypto -lssl -lcpprest -lpthread
SRC := $(shell find . -name *.cpp)
OBJ = $(SRC:%.cpp=%.o)
BIN = run
all: $(BIN)
$(BIN): $(OBJ)
$(CXX) $(LDFLAGS)
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
clean:
find . -name *.o -delete
rm -f $(BIN)
It scans for all files *.cpp
files in all subdirectories and creates corresponding *.o
files. Then it tries to link everything into a final binary, but I get the following error. I don't have any idea how to resolve this issue.
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../lib/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
Directory structure:
Makefile
sources/
directory1
...cpp
directory2
...cpp
...
main.cpp
main.cpp content:
#include <iostream>
#include <signal.h>
#include "application/application_launcher.hpp"
Alastriona::Application::Launcher launcher;
void shutdown(int signal);
int main(int argc, const char * argv[])
{
struct sigaction sa;
sa.sa_handler = &::shutdown;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
launcher.loadArguments(argc, argv);
launcher.loadConfiguration();
launcher.startApplication();
}
void shutdown(int signal)
{
launcher.stopApplication();
}
Upvotes: 0
Views: 192
Reputation: 22920
int main(int argc, const char * argv[])
Is an overload due to the constness, which is not allowed, and considered ill formed §2 by the standard. The signature you need to use is
int main(int argc, char * argv[])
Edit : Your are not using any prerequisite when trying to build the target. You should have
$(BIN): $(OBJ)
$(CXX) $^ $(LDFLAGS)
Upvotes: 1