https://seisman.github.io/how-to-write-makefile/introduction.html
not sure if it works fine.
CC = g++
CFLAGS =
PROGRAM_NAME = cli
LIBS = "-lncurses -lm -lsdl"
DEPS = $(shell find ./ -name "*.hh")
SRC = $(shell find ./ -name "*.cc")
OBJ = $(SRC:%.cc=%.o)
$(PROGRAM_NAME): $(OBJ)
$(CC) $(CFLAGS) -o $(PROGRAM_NAME) $(OBJ)
@echo "$(PACKAGE_NAME) build successfully!"
%.o: %.cc $(DEPS)
$(CC) -c $< -o $@
.PHONY: clean
clean:
rm -rf $(OBJ) $(PROGRAM_NAME)
最后用CMake
cmake_minimum_required(VERSION 3.7)
project(cli VERSION 0.0.1)
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDR_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS "-lPocoNet -lPocoFoundation")#添加你需要的编译参数,依赖库等
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# add_compile_options(-std=c++11 -Wall -lpthread -lPocoNet -lPocoFoundation) #之前一直这样试,失败的
# add_definitions("-Wall -g -lPocoNet -lPocoFoundation")
add_executable(${PROJECT_NAME}
main.cc
)