LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-08-2016, 07:23 AM   #1
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Rep: Reputation: Disabled
Adding and compiling new code in the linux kernel


This may sound like a very noob question. I'm trying to implement a UDP-based protocol in the linux kernel. I was following the UDPLite protocol implementation as a reference.

Step 1

I created a new_protocol.c in net/ipv4/
This file has a function
void _init protocol_init(void){*Code here*}

I also used
#include "udp_impl.h"
in this file as I was using some functions from the UDP protocol

Step 2

I modified the file net/ipv4/udp_impl.h to include net/new_protocol.h

Step 3

I created the file include/net/new_protocol.h where I defined the function
void protocol_init(void);

Step 4

Finally, I called this init function in net/ipv4/af_inet.c. Also, I gave an include statement in this file (af_inet.c) for net/new_protocol.h

Now when I try to build the kernel, I get an error saying
undefined reference to `protocol_init()'

What am I missing here? Is my way of including header files incorrect? Do I need to include some info in the makefile to pick up the new net/ipv4/protocol.c?
 
Old 06-08-2016, 12:33 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
It's easier to maintain a kernel module if you build it separately from the rest of the kernel, as described here:

http://lxr.free-electrons.com/source...les.txt?v=3.10
 
Old 06-09-2016, 03:28 AM   #3
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
I'd forgotten to update the Makefile

I figured out that I hadn't updated the Makefile in net/ipv4.
As an aside, compiling kernel may not take so long if CCache tool is used with make.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding/compiling a module Kernel? Xeratul Linux - General 1 01-10-2014 01:18 AM
Need help on compiling/patching adding new kernel furiousn00b Linux - General 7 09-06-2006 12:37 AM
LXer: Adding Your Code to the Kernel: A Book Excerpt LXer Syndicated Linux News 0 12-20-2005 10:16 PM
Compiling Kernel Code vbhatia_81 Programming 1 06-21-2004 06:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration