【发布时间】:2018-01-15 10:55:39
【问题描述】:
我的 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();
}
【问题讨论】:
-
你在某处有主函数吗?如果是这种情况,请在您的问题中包含其签名
-
@UmNyobe 我做到了。
-
int main(int argc, char * argv[])也许? -
可能偏离主题,但是......在你的
find命令中,名称模式几乎肯定应该用引号引起来——例如'*.cpp'。 -
@VTT 是的,这就是问题所在。但是有一些我无法理解:这个主要签名是 XCode 项目的直接端口,它在那里工作。不过它使用了 Clang。