无法在 CLion 中构建 C++ 项目
Can't build c++ project in CLion
我有一个hello-wrold项目:
main.cpp:
#include <iostream>
#include "square.h"
int main() {
int z = 5;
std::cout << square(z) << std::endl;
return 0;
}
square.cpp:
int square(int x)
{
return x * x;
}
平方h:
#ifndef SQUARE_H
#define SQUARE_H
int square(int x);
#endif //SQUARE_H
它使用来自终端的g++编译和运行:
g++ -c main.cpp
g++ -c square.cpp
g++ main.o square.o -o programm
./programm
>25
但CLion的构建最终是:
[ 50%] Linking CXX executable cpp_code
Undefined symbols for architecture x86_64:
"square(int)", 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[3]: *** [cpp_code] Error 1
make[2]: *** [CMakeFiles/cpp_code.dir/all] Error 2
make[1]: *** [CMakeFiles/cpp_code.dir/rule] Error 2
make: *** [cpp_code] Error 2
p.S.我曾经写过很长一段时间的简单c++程序(尽管有很大的停顿(,这是我第一次在这一步遇到问题。此外,还有一个自动创建的CMakeList.txt
(在VisStud中没有类似的!(CMakeList.txt:
cmake_minimum_required(VERSION 3.12)
project(cpp_code)
set(CMAKE_CXX_STANDARD 14)
add_executable(cpp_code main.cpp)
add_executable
期望创建所述可执行文件所需编译的文件列表。将square.cpp
添加到该列表中。
add_executable(cpp_code main.cpp square.cpp)
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 构建一个由C和C++文件组成的库
- llvm构建器向基本块添加终止符
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 如何跨平台将二进制资源构建到程序中?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 如何解决 Ninja c++ 构建和执行问题
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 用CMake构建C++协议
- Mingw-64 在构建和安装后不会编译 openCV 代码