CMake - Code::Blocks - 你好世界 - 基本示例
CMake - Code::Blocks - hello world - basic example
我在哪里可以找到生成要在 CMake 中加载的简单 CMake Hello World 项目的指南?
平台:Lenovo 32bit Linux Kubuntu
1) 我将使用 git 存储库:
./git/CMakeLists.txt
./git/code/CMakeLists.txt
./git/code/hello-world.c
文件包含明显的内容
2) 我会 运行 cmake
- pointing the source to the git repo indicated in 1
- configuring the repo
- generating the code-blocs-project (cbp) file in ./build
3) 所以我只需点击
- 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;
}
现在,运行 CMake 我做了:
~/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
)
如果您现在在 CodeBlocks 中打开此项目(双击项目文件),您应该会在左侧窗格中看到项目 Hello
。
默认情况下,"all" 目标是 selected。它应该出现在 GUI 顶部编译器工具栏的下拉框中。这会构建项目中指定的所有目标,但您无法 运行 - 您只能构建它。
可执行目标的名称是 "hello",如 CMake 代码 add_executable(hello hello-world.c)
中指定的那样。要 运行 可执行文件,从前面提到的下拉框中 select "hello",然后点击同一工具栏中的 "Build and run" 图标。
我在哪里可以找到生成要在 CMake 中加载的简单 CMake Hello World 项目的指南?
平台:Lenovo 32bit Linux Kubuntu
1) 我将使用 git 存储库:
./git/CMakeLists.txt
./git/code/CMakeLists.txt
./git/code/hello-world.c
文件包含明显的内容
2) 我会 运行 cmake
- pointing the source to the git repo indicated in 1
- configuring the repo
- generating the code-blocs-project (cbp) file in ./build
3) 所以我只需点击
- 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;
}
现在,运行 CMake 我做了:
~/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
)
如果您现在在 CodeBlocks 中打开此项目(双击项目文件),您应该会在左侧窗格中看到项目 Hello
。
默认情况下,"all" 目标是 selected。它应该出现在 GUI 顶部编译器工具栏的下拉框中。这会构建项目中指定的所有目标,但您无法 运行 - 您只能构建它。
可执行目标的名称是 "hello",如 CMake 代码 add_executable(hello hello-world.c)
中指定的那样。要 运行 可执行文件,从前面提到的下拉框中 select "hello",然后点击同一工具栏中的 "Build and run" 图标。