I have an include folder and an src folder, and i get a undefined reference error. My project previously worked so i have no idea what happened.
The error
$ cmake --build .
-- Configuring done
-- Generating done
-- Build files have been written to: /sdcard/dev/cpp/Bedrock++
Scanning dependencies of target Bedrock++
[ 33%] Building CXX object src/CMakeFiles/Bedrock++.dir/Server.cpp.o
[ 66%] Building CXX object src/CMakeFiles/Bedrock++.dir/main.cpp.o
[100%] Linking CXX executable Bedrock++
CMakeFiles/Bedrock++.dir/main.cpp.o: In function `main':
/sdcard/dev/cpp/Bedrock++/src/main.cpp:(.text+0x70): undefined
reference to `ChatFormat::Blue'
clang-5.0: error: linker command failed with exit code 1 (use -v to see
invocation)
make[2]: *** [src/CMakeFiles/Bedrock++.dir/build.make:121:
src/Bedrock++] Error 1
make[1]: *** [CMakeFiles/Makefile2:86:
src/CMakeFiles/Bedrock++.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Project root CMakeLists.txt
cmake_minimum_required(VERSION 2.8.7)
# Build all dependent libraries as static
project(Bedrock++)
#add_subdirectory(lib/json)
add_subdirectory(src)
add_subdirectory(include)
src CMakeLists.txt
project(bedrock++)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${PROJECT_SOURCE_DIR}/include")
file(GLOB SOURCES "*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
include CMakeLists.txt
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h")
main.cpp
#include <iostream>
#include <string>
#include "util/ChatFormat.h"
int main()
{
std::cout << "Hello World! " << ChatFormat::Blue << "hey" << std::endl;
}
The ChatFormat.h header is found in include/util/ChatFormat.h, and basically contains
static const std::string Black;
but for every different colour. Not sure if it's relevant, but the ChatFormat.cpp file contains the following throughout
const std::string ChatFormat::Delimiter = "\xc2\xa7";
const std::string ChatFormat::Black = ChatFormat::Delimiter + "0";