我的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)
它会扫描所有子目录中的所有文件*.cpp
文件,并创建相应的*.o
个文件。然后它尝试将所有内容链接到最终的二进制文件,但我得到以下错误。我不知道如何解决这个问题。
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../lib/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
目录结构:
Makefile
sources/
directory1
...cpp
directory2
...cpp
...
main.cpp
main.cpp内容:
#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();
}
答案 0 :(得分:1)
int main(int argc, const char * argv[])
标准是which is not allowed, and considered ill formed §2的常量引起的过载。您需要使用的签名是
int main(int argc, char * argv[])
编辑:尝试构建目标时,您没有使用任何先决条件。 你应该
$(BIN): $(OBJ)
$(CXX) $^ $(LDFLAGS)