Я пытаюсь построить проект со следующим файлом
cmake_minimum_required(VERSION 3.1.3)
project(terminalTest)
set(MainSource "/Users/username/Coding/Major Projects/projectname/Backend")
set(TerminalSource "/Users/username/Coding/Major Projects/projectname/Terminal")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
#Bring the headers, such as Student.h into the project
include_directories(${MainSource} ${TerminalSource})
#Can manually add the sources using the set command as follows:
#set(SOURCES src/mainapp.cpp src/Student.cpp)
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES
${MainSource}/*.cpp
${TerminalSource}/*.cpp
)
add_executable(terminalTest ${SOURCES})
, который я использую CMAKE GUI со следующей конфигурацией для настройки и создания файла сборки
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.17
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Disable VCS-based implicit rules.
% : %,v
# Disable VCS-based implicit rules.
% : RCS/%
# Disable VCS-based implicit rules.
% : RCS/%,v
# Disable VCS-based implicit rules.
% : SCCS/s.%
# Disable VCS-based implicit rules.
% : s.%
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /Applications/CMake.app/Contents/bin/cmake
# The command to remove a file.
RM = /Applications/CMake.app/Contents/bin/cmake -E rm -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = "/Users/username/Coding/Major Projects/projectname/Terminal"
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = "/Users/username/Coding/Major Projects/projectname/Terminal/Build"
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/Applications/CMake.app/Contents/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/Applications/CMake.app/Contents/bin/cmake-gui -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start "/Users/username/Coding/Major Projects/projectname/Terminal/Build/CMakeFiles" "/Users/username/Coding/Major Projects/projectname/Terminal/Build/CMakeFiles/progress.marks"
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start "/Users/username/Coding/Major Projects/projectname/Terminal/Build/CMakeFiles" 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named terminalTest
# Build rule for target.
terminalTest: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 terminalTest
.PHONY : terminalTest
# fast build rule for target.
terminalTest/fast:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/build
.PHONY : terminalTest/fast
EngineTester.o: EngineTester.cpp.o
.PHONY : EngineTester.o
# target to build an object file
EngineTester.cpp.o:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/EngineTester.cpp.o
.PHONY : EngineTester.cpp.o
EngineTester.i: EngineTester.cpp.i
.PHONY : EngineTester.i
# target to preprocess a source file
EngineTester.cpp.i:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/EngineTester.cpp.i
.PHONY : EngineTester.cpp.i
EngineTester.s: EngineTester.cpp.s
.PHONY : EngineTester.s
# target to generate assembly for a file
EngineTester.cpp.s:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/EngineTester.cpp.s
.PHONY : EngineTester.cpp.s
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.o: Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.o
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.o
# target to build an object file
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.o:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.o
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.o
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.i: Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.i
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.i
# target to preprocess a source file
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.i:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.i
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.i
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.s: Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.s
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.s
# target to generate assembly for a file
Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.s:
$(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.s
.PHONY : Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... terminalTest"
@echo "... EngineTester.o"
@echo "... EngineTester.i"
@echo "... EngineTester.s"
@echo "... Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.o"
@echo "... Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.i"
@echo "... Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
Что меня больше всего смущает во всем этом, так это то, что этот make-файл не создает двоичный файл, даже если он заявляет об этом.
[ 33%] Linking CXX executable terminalTest
clang: warning: -Wl,-search_paths_first: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -Wl,-headerpad_max_install_names: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: CMakeFiles/terminalTest.dir/Users/username/Coding/Major_Projects/projectname/Backend/Tweaking.cpp.o: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: CMakeFiles/terminalTest.dir/EngineTester.cpp.o: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' [-Wunused-command-line-argument]
[100%] Built target terminalTest
Не найдено ни одного файла, сгенерированного с помощью команды make.
Мне пришлось добавить флаг - c, потому что в противном случае я получил Пучок неопределенных символов из кода в внутренней папке (возможно, ему не понравилось, что заголовки в этой папке .hpp
и папки в терминале папка .h
?)
Вы вообще можете понять, почему этот скрипт не может создавать двоичный файл?
Для справки конечная цель - взять движок, определенный в папке Backend, и протестировать это с небольшим количеством кода в папке Terminal в исполняемом файле, который я могу запустить с помощью gdb / valgrind / gprof.
Стоит отметить, что если я не использую флаг "- c", я получаю следующее ошибка
[ 33%] Linking CXX executable terminalTest
Undefined symbols for architecture x86_64:
"Engine::deconstruct()", referenced from:
_main in EngineTester.cpp.o
"Engine::instance", referenced from:
Engine::shared() in EngineTester.cpp.o
"Engine::setCount(int)", referenced from:
_main in EngineTester.cpp.o
"Engine::simulate()", referenced from:
_main in EngineTester.cpp.o
"Engine::Engine()", referenced from:
Engine::shared() in EngineTester.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [terminalTest] Error 1
make[1]: *** [CMakeFiles/terminalTest.dir/all] Error 2
make: *** [all] Error 2
EngineTester.cpp
находится в папке «Терминал», а определение класса Engine находится в Backend/Engine/Engine.hpp
.