Re: compile warning with EXPORT_SYMBOL



In article <43D951B4.64E00F3E@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Kasper Dupont
<53560654856913929293@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> Steve Sivier wrote:
> >
> > and module_function() is declared extern in a header that moduleB
> > includes. During the compile of moduleB (actually the linking), I get a
> > warning that moduleA_function isn't defined,
>
> Could you post a minimal example demonstrating this problem?
> (Take a copy of moduleB and remove all code unrelated to the
> warning).

Sure. And here's the warning I get when trying to build moduleB:
Building modules, stage 2.
MODPOST
*** Warning: "moduleA_function" [/moduleB/moduleb.ko] undefined!

Thanks for any help,
Steve



===== moduleB.c =====
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <asm/io.h>
#include "moduleA.h"

static int moduleB_init(void);
static void moduleB_exit(void);

static struct file_operations moduleB_fops = {
owner: THIS_MODULE,
};

static int major_number;

/**
* Function called when driver is loaded.
*
* @return 0 on success, less than 0 on failure.
*/
static int
moduleB_init(void)
{
int result;

major_number = register_chrdev(0, "moduleB", &moduleB_fops);

result = moduleA_function();

return (0);
}

/**
* Function called when driver is unloaded.
*/
static void
moduleB_exit(void)
{
(void) unregister_chrdev(major_number, "moduleB");
}

module_init(moduleB_init);
module_exit(moduleB_exit);

MODULE_LICENSE("Proprietary");

===== moduleA.h =====
#ifndef _MODULEA_H
#define _MODULEA_H

/*
* Header file describing the interface to the FPGA driver
*/

#ifdef __KERNEL__
#include <linux/ioctl.h>
#include <linux/types.h>
#else
#include <sys/ioctl.h>
#include <inttypes.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern int moduleA_function(void);

#ifdef __cplusplus
}
#endif

#endif /* _MODULEA_H */

===== moduleA.c (not really needed for the example) =====
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <asm/io.h>
#include "moduleA.h"

static int moduleA_init(void);
static void moduleA_exit(void);

static struct file_operations moduleA_fops = {
owner: THIS_MODULE,
};

static int major_number;

static int moduleA_value;

EXPORT_SYMBOL(moduleA_function);

/**
* Function called when driver is loaded.
*
* @return 0 on success, less than 0 on failure.
*/
static int
moduleA_init(void)
{
major_number = register_chrdev(0, "moduleA", &moduleA_fops);

moduleA_value = 42;

return (0);
}

/**
* Function called when driver is unloaded.
*/
static void
moduleA_exit(void)
{
(void) unregister_chrdev(major_number, "moduleA");
}

static int
moduleA_function(void)
{
return (moduleA_value);
}

module_init(moduleA_init);
module_exit(moduleA_exit);

MODULE_LICENSE("Proprietary");
.



Relevant Pages