CMake-代码::块-Hello World-基本示例 [英] CMake - Code::Blocks - hello world - basic example
问题描述
在哪里可以找到生成要在CMake中加载的CMake Hello World项目的指南?
Where can I find a guide to generate a simple CMake Hello World project to be loaded in CMake?
平台:Lenovo 32bit Linux Kubuntu
platform: Lenovo 32bit Linux Kubuntu
./git/CMakeLists.txt
./git/code/CMakeLists.txt
./git/code/hello-world.c
其中文件包含明显的内容
where the files contain the obvious content
- pointing the source to the git repo indicated in 1
- configuring the repo
- generating the code-blocs-project (cbp) file in ./build
中生成code-blocs-project(cbp)文件),所以我只需单击
- 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!"
推荐答案
因此,只是为了确认文件的明显内容;这就是我所拥有的:
So, just to confirm the files' obvious content; here's what I have:
~/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;
}
现在,要运行CMake,我做了:
Now, to run CMake I did:
~/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
您可以看到已生成CodeBlocks项目文件( Hello.cbp
)
which you can see has resulted in a CodeBlocks project file (Hello.cbp
)
如果您现在打开此项目在CodeBlocks中(双击项目文件),您应该在左窗格中看到项目 Hello
。
If you now open this project in CodeBlocks (double click on the project file), you should see the project Hello
on the left pane.
默认情况下,选择全部目标。它应显示在GUI顶部的编译器工具栏中的下拉框中。这样可以构建项目中指定的所有目标,但您无法运行它-您只能构建它。
By default, the "all" target is selected. It should appear in a drop-down box in the compiler toolbar at the top of the GUI. This builds all the targets specified in the project, but isn't something you can run - you can only build it.
可执行目标的名称为 hello,如CMake代码 add_executable(hello hello-world.c)$ c $所指定。 c>。要运行可执行文件,请从前面提到的下拉框中选择 hello,然后在同一工具栏中单击生成并运行图标。
The executable target's name is "hello", as specified in the CMake code add_executable(hello hello-world.c)
. To run the executable, select "hello" from the drop-down box mentioned before, and then hit the "Build and run" icon in the same toolbar.
这篇关于CMake-代码::块-Hello World-基本示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!