Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux and C Programming "undefined reference to function"

Posted on 2004-09-05
5
Medium Priority
?
645 Views
Last Modified: 2010-04-22
Hi

I've been working on the linux kernel itself. Let' me describe the problem. It's kind of long-winded.

I have modified the open.c file by adding in the following lines

out:
      #include <linux/bsm/audit-CHDIR.c>
      return error;

and at the beginning of this modified open.c file, I've added

#ifdef CONFIG_BSM_AUDIT
#include <linux/bsm/audit.h>
#endif

Inside the audit-CHDIR.c file, we have the line

      audit(&header, &event);

and inside the audit.h file, we have the line

int audit(audit_header*, void*);

All is well so far, until I compile the code. Apparently, compilation works fine because the audit function is declared in the audit.h header file. but an error occurred during the linking stage ( i assume this error message only occurs at linking stage)

fs/fs.o(.text+0x764): In function `sys_chdir':
: undefined reference to `audit'

The reason I can think of is that there is no way for the build system to know where audit function is DEFINED. The compiler knows that audit function is DECLARED in the audit.h file, but the linker has no idea that audit function is defined in /usr/src/linux/kernel/audit.c. And I don't know how to let the linker know about this.

Thanks for your help.


0
Comment
Question by:feelite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 2

Expert Comment

by:gysbert1
ID: 11987248
You would probably need to add a depency on audit.o in the Makefile, this will translate to a make auto-rule which will compile auto.c and link it in. I only have the 2.6.5 kernel source handy right now, but in that you'd probably want to edit /usr/src/linux/kernel/Makefile, and add audit.o to the obj-y line right at the beginning of the file.
0
 

Author Comment

by:feelite
ID: 11993399
hi, thanks for reply. (btw, i'm using 2.4 kernel, FC1)

The only change I made to /usr/src/linux/kernel/Makefile is the addition of the following lines

ifeq ($(CONFIG_BSM_AUDIT),y)
OX_OBJS += audit.o
endif

I suppose it tells something about looking for the audit.o while linking this kernel.o. However, I'm new to the GNU Make system, the manual at the official site does not talk about things like OX_OBJS and stuff.

Also, how does the make system know where to look for the audit.o?


The full /usr/src/linux/kernel/Makefile reads the following


#
# Makefile for the linux kernel.
#
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definitions are now in the main makefile...

O_TARGET := kernel.o

export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o cpufreq.o profile.o module.o

obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o profile.o \
          module.o exit.o itimer.o info.o time.o softirq.o resource.o \
          sysctl.o acct.o capability.o ptrace.o timer.o user.o \
          signal.o sys.o kmod.o context.o \
          futex.o pid.o kksymoops.o

obj-$(CONFIG_UID16) += uid16.o
obj-$(CONFIG_MODULES) += ksyms.o
obj-$(CONFIG_PM) += pm.o
obj-$(CONFIG_CPU_FREQ) += cpufreq.o
obj-$(CONFIG_IKCONFIG) += configs.o
obj-$(CONFIG_KALLSYMS) += kallsyms.o

ifeq ($(CONFIG_BSM_AUDIT),y)
OX_OBJS += audit.o
endif

ifneq ($(CONFIG_IA64),y)
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
# needed for x86 only.  Why this used to be enabled for all architectures is beyond
# me.  I suspect most platforms don't need this, but until we know that for sure
# I turn this off for IA-64 only.  Andreas Schwab says it's also needed on m68k
# to get a correct value for the wait-channel (WCHAN in ps). --davidm
#
# Some gcc's are building so that O(1) scheduler is triple faulting if we
# build -O2. (Turns out to be a CPU issue. Update your microcode if you hit it)
#
CFLAGS_sched.o := $(PROFILING) -fno-omit-frame-pointer
endif

include $(TOPDIR)/Rules.make

configs.o: $(TOPDIR)/scripts/mkconfigs configs.c
      $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DEXPORT_SYMTAB -c -o configs.o configs.c

$(TOPDIR)/scripts/mkconfigs: $(TOPDIR)/scripts/mkconfigs.c
      $(HOSTCC) $(HOSTCFLAGS) -o $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/scripts/mkconfigs.c

configs.c: $(TOPDIR)/.config $(TOPDIR)/scripts/mkconfigs
      $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/.config configs.c
0
 
LVL 2

Accepted Solution

by:
gysbert1 earned 400 total points
ID: 11993842
GNU make defines a number of auto rules for making certain things, there are options to list them and override them but I can't remember how. One of the auto-rules tells make how to generate an object file from a c file, so if you have a .o dependency somewhere which doesn't exist, it will look for a corresponding .c and compile it to an object file automatically.

OX_OBJS is nothing specific to GNU make AFAIK, it is just a variable to which you have added audit.o. I don't have FC1 or 2.4.x anymore, but I can't see OX_OBJS being used in the 2.6 makefile, I would have thought you should say something like
obj-y += audit.o
but I don't know the kernel make system well at all.
BTW, this
http://www.gnu.org/software/make/manual/html_chapter/make.html
is a very good GNU make reference/tutorial IMHO.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question