For an academic project, I'm looking to add a source file (myfile.c) to the kernel/
directory, the same directory as exit.c
and fork.c
. The build system does not appear to automatically pick up the new file, as I'm hitting "undefined reference" link errors to functions defined in myfile.c
. How could I get this file incorporated?
*** Execute 'make' to start the build or try 'make help'. Now the kernel is configured and you can build and install it by command: The first make command compile the source code files. The -j option make make compile in parallel using concurrent tasks of at most number of the processors in the system so that the compilation can be much faster.
Also, the kernel must have been built with modules enabled. If you are using a distribution kernel, there will be a package for the kernel you are running provided by your distribution. An alternative is to use the “make” target “modules_prepare.” This will make sure the kernel contains the information required.
The Linux kernel source code comes with the default configuration. However, you can adjust it to your needs. To do so, follow the steps below: 1. Navigate to the linux-5.9.6. directory using the cd command: 2. Copy the existing configuration file using the cp command: 3. To make changes to the configuration file, run the make command:
The kernel Makefiles are designed to be run with GNU Make. The Makefiles use only the documented features of GNU Make, but they do use many GNU extensions. GNU Make supports elementary list-processing functions. The kernel Makefiles use a novel style of list building and manipulation with few “if” statements.
You need to add a corresponding object file to the kernel/Makefile
. If you have a configuration variable for your code, then you would use:
obj-$(CONFIG_ZERO_STIMULUS_FEATURE) += zerostimulus.o
If you're building in your code without a configuration variable, then you'll just add it to the obj-y
variable:
obj-y += zerostimulus.o
The configuration variable expands to y
, m
, or n
, depending if the feature is built-in, built as a module, or turned off. Then the obj-y
, obj-m
, variables are built.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With