我的生成文件:
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();
}
最佳答案
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)
关于c++ - Makefile 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48261575/