Solved

Linux and C Programming "undefined reference to function"

Posted on 2004-09-05
5
608 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
  • 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now