How to check Kconfig flag in C source code

597 Views Asked by At

I am new to Linux and Kconfig.

I have a config enabled in a Kconfig file as follows :

config ENABLE_MY_CONFIG
    bool "Enable my config"
    default n
    help
     Say Y if you want to enable my config

I don't have everything included here, but It causes conditional compilation of a my_lib.c C source file by adding this to my Makefile :

obj-$(ENABLE_MY_CONFIG) += my_lib.o

However, I have a test application for testing all my code which must be in one C file.

How can I call functions in my my_lib.c file and test only if ENABLE_MY_CONFIG is enabled, and don't call the functions otherwise? Thanks in advance.

1

There are 1 best solutions below

2
HardcoreHenry On

You can use #ifdef CONFIG_ENABLED_MY_CONFIG within the kernel C code.

If you want to test it outside of the kernel, you can likely write something to parse the .config file to see if it's set in there.