Cmake体系结构x86_64链接器错误的未定义符号

时间:2020-03-13 02:18:56

标签: c++ cmake linker c++17 linker-errors

我有一个包含以下文件的简单C ++项目

├── include
│   └── project_name
│       └── node.h
├── src
│   ├── main.cpp
│   └── node.cpp
├── test
└── CMakeLists.txt

在CmakeLists.txt中,我有

cmake_minimum_required(VERSION 3.15)

project(project_name)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# include files
include_directories(
    include
)

# target
add_executable(
    maple
    src/node.cpp
    src/main.cpp
)

如您所见。这是一个非常简单的项目,但是我得到了

[ 33%] Linking CXX executable maple
Undefined symbols for architecture x86_64:
  "Node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::print()", referenced from:
      _main in main.cpp.o
  "Node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Node(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      _main in main.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]: *** [maple] Error 1
make[1]: *** [CMakeFiles/project_name.dir/all] Error 2
make: *** [all] Error 2

我想问的三个问题是

  1. 我需要在CMakeLists.txt中进行哪些更改以解决此问题?

  2. 如何检查使用的是哪个C ++编译器?

  3. 它实际上是用C ++ 17编译的吗?如何检查?

非常感谢您抽出宝贵的时间

0 个答案:

没有答案