sraddhaj
sraddhaj

Reputation: 591

undefined reference to " `function` in the network device interface to the userspace."

I want to use the network device interface exported by the network driver module. This is my program devget.c

 #include<stdio.h>
 #include<linux/netdevice.h>

  void main(void)
  {
     struct net_device* device;

     device = dev_get_by_name("eth0");
     if (device == NULL)
         printf("device is NULL\n");
     else
         printf("This is a success story\n");
   }

I am cross compiling this. undefined reference to `dev_get_by_name'. Now this function is defined as a prototype in the /linux/netdevice.h file . I compile this with agcc giving the include paths in the script.

Upvotes: 0

Views: 571

Answers (1)

ugoren
ugoren

Reputation: 16441

You seem to be building a user space program, rather than a kernel module.

User space programs can't use kernel functions. They can only use functions from libc or other libraries.

You'll need to compile your code as a kernel module.
This changes several things - you don't have a main function (instead you have init_module, which isn't the same), and the compilation process is different (not just gcc -o myprog myprog.c).

I suggest you read a basic book about kernel development.

Upvotes: 1

Related Questions