PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] how to compile multiple files together when one of them is a Linux Kernel module

 August 23, 2022     c, module     No comments   

Issue

There are several files in my folder: module.c , uart.c , uart.h .

In the file module.c I have #include "uart.h".

How do I make a makefile? regular makefile:

obj-m := module.o
KERNELDIR = /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
echo "bulding module for intel architecture:" 

when I execute make on the makefile above, it gives me an error that it does not know the functions from uart.c, although I have include in the code


Solution

To build a Linux kernel module from two (or more) .c files, module.c and uart.c:

ifneq ($(KERNELRELEASE),)

obj-m := mymodule.o
mymodule-objs := module.o uart.o

else

KERNELDIR ?= "/lib/modules/$(shell uname -r)/build"

all:
    $(MAKE) -C "$(KERNELDIR)" M="$(CURDIR)" modules

install:
    $(MAKE) -C "$(KERNELDIR)" M="$(CURDIR)" modules_install

clean:
    $(MAKE) -C "$(KERNELDIR)" M="$(CURDIR)" clean

endif

The above will build a module named mymodule.ko. For kernel modules composed of more than one object file (module.o and uart.o in this case), the name of the built module object file (mymodule.o in this case) must be different from the names of the component object files.



Answered By - Ian Abbott
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing