Unable to reference sysfs on Linux.

I am porting C code to a linux system but I am unable to link a call to the sysfs function.

An excerpt from my code is:

if (fstat(fileno(TrCtl.Fp), &fsstat) != -1)
{
    (void) sysfs(1, fsname);
    if (strcmp(fsname, "nfs"))
    {
        (void) lockf(fileno(TrCtl.Fp), F_LOCK, 0L);
    }
}

This code is compiled into a library, but when linked to the main executable I get the following error:

/usr/bin/gcc -o oracle_connect oracle_connect.o -L /usr/lib -L /home/mb/build/dev/Lib -ltrace /home/mb/build/dev/Lib/libtrace.a

(traceopen.o)(.text+0x172): In function `traceopen':
: undefined reference to `sysfs'
collect2: ld returned 1 exit status

The man page suggests that I do not need to reference any particular headers or files.

I have checked the libc library and it does contain sysfs.o,
but I am at loss as how to reference it.

Does any one know? Is it even possible in Linux?

My versions are:

Red Hat Enterprise Linux AS release 3 (Taroon)
Linux ccabccesd2 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i38 6 GNU/Linux

Thanks

/usr/bin/gcc -o oracle_connect oracle_connect.o -L /usr/lib \
     -L /home/mb/build/dev/Lib -ltrace /home/mb/build/dev/Lib/libtrace.a

/usr/bin/gcc -o oracle_connect oracle_connect.o  \
     -L /home/mb/build/dev/Lib -ltrace /home/mb/build/dev/Lib/libtrace.a \
     -L /usr/lib

Try making ld search for symbols in /usr/lib after you declare all your symbols.

Like this?

/usr/bin/gcc    -DTRACE_ON -I/home/app/oracle/product/10.1.0/Db_1/precomp/public
 -I/home/mb/build/dev/Include -c ec2pc.c

/usr/bin/gcc -o ec2pc ec2pc.o -L /home/app/oracle/product/10.1.0/Db_1/lib -lsqlplus -L /home/mb/build/dev/Lib -ltrace -L /usr/lib
/home/mb/build/dev/Lib/libtrace.a(traceopen.o)(.text+0x172): In function `traceopen':
: undefined reference to `sysfs'
collect2: ld returned 1 exit status

Thanks for the idea, but no. It makes no difference.

On my box sysfs in defined in libc.0 which is a link to the current version of libc.
Which is where you'd expect it to be....
try to find where sysfs is located:

 for file in *
 do
 nm $file | grep sysfs
 if [ $? -eq 0 ]; then
       echo $file
 fi
 done

look for the entry point:
sysfs | 0|sdef |code |$CODE$

If all else fails then link against libc.a as the very last step in the link statement.
Assuming that nm shows it to be in there. Your compiler does support sysfs ie., it's in the man pages?

Yay, sysfs is indeed in the man pages and describes 3 variants.

I had already searched through the libraries using ar, and found sysfs.o in libc.a! Within the same library archive are the standard goodies such as printf and I have no trouble with this function.

Is it possible that it is not supported? In my man page there is a cryptic statement which may suggest this: "There is no libc or glibc support."

It's very possible it is not supported. Unix systems have various "standards" like SVS2, POSIX.

sysfs is not POSIX according to Steven's book edition #2.