2024-04-10 12:21:46 +08:00
# create a new project
The 'examples/demo1' folder is a 'Hello, World!' project that can be used as a template for quickly creating your own project by duplicating this folder.
## File tree
``` bash
demo1
2024-04-26 09:45:12 +08:00
├── SConstruct
2024-04-10 12:21:46 +08:00
├── config_defaults.mk
├── main
│ ├── include
│ │ └── main.h
│ ├── Kconfig
2024-04-26 09:45:12 +08:00
| ├── SConstruct
2024-04-10 12:21:46 +08:00
│ └── src
│ └── main.c
` ``
- **main** Main code directory
2024-04-26 09:45:12 +08:00
- **main/SConstruct** CMake files for the main code, requiring manual addition of dependency folders.
2024-04-10 12:21:46 +08:00
- **config_defaults.mk** Default configuration files, storing default component configurations.
2024-04-26 09:45:12 +08:00
- **SConstruct** Project's startup entry point, no need for modifications.
2024-04-10 12:21:46 +08:00
## Creating a project example
` ``bash
# Enter the 'examples' folder.
cd examples
2024-09-11 16:07:19 +08:00
# Copy the 'hello_world' folder to 'demo1'.
cp hello_world demo1 -r
2024-04-10 12:21:46 +08:00
2024-09-11 16:07:19 +08:00
# Enter the 'demo1' directory.
cd demo1
2024-04-10 12:21:46 +08:00
# Edit 'main/src/main.c' and input the following content.
2024-09-11 16:07:19 +08:00
############################### demo1/main/src/main.c ###############################
#include <stdio.h>
2024-04-10 12:21:46 +08:00
2024-09-11 16:07:19 +08:00
int main(int argc,char *argv[])
{
printf("hello world!\r\n");
return 0;
}
2024-04-10 12:21:46 +08:00
#################################################################################################
` ``
2024-09-11 16:07:19 +08:00
Execute in the 'demo1' directory.
2024-04-10 12:21:46 +08:00
Then execute the compilation.
` `` bash
2024-04-26 09:45:12 +08:00
scons
2024-04-10 12:21:46 +08:00
` ``
2024-09-11 16:07:19 +08:00
After successful compilation, the 'demo1' executable file will be generated in the 'examples/demo1/dist' folder.
2024-04-10 12:21:46 +08:00
2024-09-11 16:07:19 +08:00
Run the 'demo1' program.
2024-04-10 12:21:46 +08:00
` ``bash
2024-09-11 16:07:19 +08:00
./dist/demo1
2024-04-10 12:21:46 +08:00
` ``
## Cross-compilation
` `` bash
# Complete clean
2024-04-26 09:45:12 +08:00
scons distclean
2024-04-10 12:21:46 +08:00
2024-04-26 09:45:12 +08:00
# Set the cross-compiler according
scons menuconfig
2024-04-10 12:21:46 +08:00
# Compile
2024-04-26 09:45:12 +08:00
scons
2024-04-10 12:21:46 +08:00
# Push files according to the Makefile preset
2024-04-26 09:45:12 +08:00
scons push
2024-04-10 12:21:46 +08:00
# Simply enter the development environment and execute
` ``