一、是什么?
预处理:是指在进行加工前准备工作.
gcc 选项 文件名字
二、使用步骤
1.向源码传参
gcc -save-temps -DSENSOR_TYPE=SONY_IMX477_MIPI_8M_30FPS_12BIT hello.c -o hello
代码如下(示例):
#include <stdio.h>
#include <stdlib.h>
typedef enum hiSAMPLE_SNS_TYPE_E{
SONY_IMX477_MIPI_12M_30FPS_12BIT,
SONY_IMX477_MIPI_9M_50FPS_10BIT,
SONY_IMX477_MIPI_8M_60FPS_12BIT,
SONY_IMX477_MIPI_8M_30FPS_12BIT,
SONY_IMX290_MIPI_2M_30FPS_12BIT,
SONY_IMX290_MIPI_2M_30FPS_12BIT_WDR3TO1,
SONY_IMX334_SLAVE_MIPI_8M_30FPS_12BIT,
SONY_IMX334_MIPI_8M_30FPS_12BIT,
SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1,
SONY_IMX277_SLVS_8M_120FPS_10BIT,
SONY_IMX277_SLVS_8M_30FPS_12BIT,
SONY_IMX277_SLVS_8M_60FPS_12BIT,
SONY_IMX277_SLVS_12M_30FPS_12BIT,
SONY_IMX277_SLVS_2M_240FPS_12BIT,
FPGA_CYCLONE_LVDS_XM_XFPS_16BIT_1080P,
FPGA_CYCLONE_LVDS_XM_XFPS_16BIT_720P,
SAMPLE_SNS_TYPE_BUTT,
} SAMPLE_SNS_TYPE_E;
int main()
{
printf("SENSOR_TYPE type is %d \n",SENSOR_TYPE);
return 0;
}
2.条件编译
#if (xxxx == 1)
#endif
#include <stdio.h>
#include <stdlib.h>
#define CONFIG_USB_DEVICE (1)
int cleanup_before_linux(void)
{
return 0;
}
void udc_disconnect(void)
{
printf("\n udc_disconnect\n\n");
}
static void announce_and_cleanup(void)
{
//#ifdef CONFIG_USB_DEVICE
#if (CONFIG_USB_DEVICE == 1)
udc_disconnect();
#endif
printf("\nStarting kernel ...\n\n");
cleanup_before_linux();
}
int main()
{
announce_and_cleanup();
return 0;
}
条件编译二
#ifdef xxxx
#endif
#include <stdio.h>
#include <stdlib.h>
int cleanup_before_linux(void)
{
return 0;
}
void udc_disconnect(void)
{
printf("\n udc_disconnect\n\n");
}
static void announce_and_cleanup(void)
{
#ifdef CONFIG_USB_DEVICE
udc_disconnect();
#endif
printf("\nStarting kernel ...\n\n");
cleanup_before_linux();
}
int main()
{
announce_and_cleanup();
return 0;
}