CMake-Code::Blocks-helloworld-basic示例
在哪里可以找到生成要加载到CMake中的简单CMake Hello World项目的指南 平台:联想32位Linux Kubuntu 1) 我将使用git回购: 其中文件包含明显的内容 2) 我会运行cmake 3) 所以我只需点击CMake-Code::Blocks-helloworld-basic示例,cmake,codeblocks,Cmake,Codeblocks,在哪里可以找到生成要加载到CMake中的简单CMake Hello World项目的指南 平台:联想32位Linux Kubuntu 1) 我将使用git回购: 其中文件包含明显的内容 2) 我会运行cmake 3) 所以我只需点击 因此,只需确认文件的明显内容;以下是我所拥有的: ~/devel/example $ tree . . ├── build └── git ├── CMakeLists.txt └── code ├── CMakeLists.txt
因此,只需确认文件的明显内容;以下是我所拥有的:
~/devel/example $ tree .
.
├── build
└── git
├── CMakeLists.txt
└── code
├── CMakeLists.txt
└── hello-world.c
3 directories, 3 files
~/devel/example $ cat git/CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Hello)
add_subdirectory(code)
~/devel/example $ cat git/code/CMakeLists.txt
add_executable(hello hello-world.c)
~/devel/example $ cat git/code/hello-world.c
#include <stdio.h>
int main() {
printf("Hello stack overflowers!\n");
return 0;
}
您可以看到它产生了一个CodeBlocks项目文件(Hello.cbp
)
如果现在在代码块中打开此项目(双击项目文件),您应该会在左窗格中看到项目Hello
默认情况下,选择“全部”目标。它应该出现在GUI顶部编译器工具栏的下拉框中。这将构建项目中指定的所有目标,但不是您可以运行的—您只能构建它
可执行目标的名称为“hello”,如CMake code
add\u executable(hello hello world.c)
中所述。要运行可执行文件,请从前面提到的下拉框中选择“hello”,然后点击同一工具栏中的“Build and run”图标。第2点是正确的,第3点只是编写程序的问题。问题就在第1点:因此,您需要知道如何编写一个cmake项目,该项目允许您从源文件创建一些可执行文件和库,以便您可以从中生成代码块项目,然后在代码块中构建和运行项目。所以,现在你知道该搜索什么了:一个好的cmake教程。问题是没有一个cmake教程是简单的,并且包含了文件夹结构的想法,感谢big time Fraser提供的好例子!你应该接受弗雷泽伟大的回答安东尼奥:谢谢你指出这一点,干杯:-)我记得我在过去的一段时间里一直在努力学习基础知识,这一点都不好玩!您只想进入编写代码的部分,而不是在设置东西时乱来。
- pointing the source to the git repo indicated in 1
- configuring the repo
- generating the code-blocs-project (cbp) file in ./build
- the cbp link in ./build
- compile the project in c::b and run a
- very basic console program spitting out, you guessed it: "Hello stack overflowers!"
~/devel/example $ tree .
.
├── build
└── git
├── CMakeLists.txt
└── code
├── CMakeLists.txt
└── hello-world.c
3 directories, 3 files
~/devel/example $ cat git/CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Hello)
add_subdirectory(code)
~/devel/example $ cat git/code/CMakeLists.txt
add_executable(hello hello-world.c)
~/devel/example $ cat git/code/hello-world.c
#include <stdio.h>
int main() {
printf("Hello stack overflowers!\n");
return 0;
}
~/devel/example $ cd build/
~/devel/example/build $ cmake ../git -G"CodeBlocks - Unix Makefiles"
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fraser/devel/example/build
~/devel/example/build $ ls
CMakeCache.txt CMakeFiles cmake_install.cmake code Hello.cbp Makefile