`nfsInit` from the librtemsNfs.h file cannot be linked?

Ben Dart Ben.Dart at adept.com
Tue Feb 2 22:05:16 UTC 2016


I am trying to use the RTEMS NFS Client with a POWER PC on RTEMS 4.9.2. I know it is old, but unfortunately our company is not ready to upgrade yet.

---- Our Design ----
We don't expose the RTEMS command line in our program, so we would like to be able to use the nfs interface directly. The RTEMS libs provides librtemsNfs.h which contains functions for implementing nfs clients. The implementations for these functions are in nfs.c which is compiled to create 1 of 2 libs:

-        libnfs.a

-        nfs.rel
Both are needed to build. As part of our code we are using the function nfsInit(... which is declared in librtemsNfs.h and defined in nfs.c.

---- The error ----
So the error is pretty obvious. When we build we get the linker error:

D:\Git\nfs_stuff\Src\RTEMS_proj/init/srvinit.cpp:453: undefined reference to `nfsInit(int, int)'
collect2: ld returned 1 exit status

---- Attempts to link these libraries ----
In order to link these we have tried multiple ways:

The recommended method is to link with -lnfs:

    XCPPFLAGS += -lnfs

and doing so yields a nice long and complex build command:

    powerpc-rtems4.9-g++ -g -Wall -g -mcpu=603e -mstrict-align -meabi -msdata -fno-common ... -MANY_PREPROCESSOR_ARGUMENTS ... -MANY_INCLUDE_FILES ... Map=./exe/srvevp.map -lc -lm --gc-sections -lnfs -mcpu=603e -mstrict-align -meabi ... -MANY_OBJECT_FILES ... ./exe/obj/srvinit.o ... -MANY_MORE_OBJECT_FILES

Our compile and link command has -lnfs, before the inclusion of the offending object file (srvinit.o). But we still get the linker error.

I tried to link by path directly to the .a and .rel file. First I did this:

    NFS_LIB = $(RTEMS_MAKEFILE_PATH)/lib/libnfs.a
    NFS_REL_LIB = $(RTEMS_MAKEFILE_PATH)/lib/nfs.rel

We also did this by adding: /c/rtems-4.9/powerpc-rtems4.9/5200/lib/libnfs.a /c/rtems-4.9/powerpc-rtems4.9/5200/lib/nfs.rel to the command line. We added it both before and after the offending object file. We also tried with the -L command to force linking by path. All of this results in the same error.

---- Some other information ----
When removing the direct link of the libnfs.a (from LINK_OBJS) we lose the ability to build even without direct use of the nfs client functions. This is very odd, it seems to me you should only need to the -lnfs to build the command line options, but even without this flag it builds successfully. Without the direct include we get the error:

c:/rtems-4.9/powerpc-rtems4.9/5200/lib\librtemscpu.a(libshell_a-main_mount_nfs.o): In function `rtems_shell_nfs_mounter':
e:\CCNET\rtems-4.9\Trunk\build_5200\powerpc-rtems4.9\c\adept_5200\cpukit\libmisc/../../../../../../rtems-4.9.2/c/src/../../cpukit/libmisc/shell/main_mount_nfs.c:46: undefined reference to `rpcUdpInit'
e:\CCNET\rtems-4.9\Trunk\build_5200\powerpc-rtems4.9\c\5200\cpukit\libmisc/../../../../../../rtems-4.9.2/c/src/../../cpukit/libmisc/shell/main_mount_nfs.c:51: undefined reference to `nfsInit'
e:\CCNET\rtems-4.9\Trunk\build_5200\powerpc-rtems4.9\c\5200\cpukit\libmisc/../../../../../../rtems-4.9.2/c/src/../../cpukit/libmisc/shell/main_mount_nfs.c:58: undefined reference to `nfsMount'
collect2: ld returned 1 exit status
Which is the rtems shell code failing to link. If we add the /c/rtems-4.9/powerpc-rtems4.9/5200/lib/libnfs.a /c/rtems-4.9/powerpc-rtems4.9/5200/lib/nfs.rel to the end of the build line, then everything succeeds.

To re-iterate, to build the command line functions you need to directly include the nfs .a and .rel files, you DO NOT need to use -lnfs.

---- The question ----
So the first and most obvious question is, why is this not linking, even when i explicitly give the library files? My thoughts on this are, perhaps the files do not include the definitions for the functions i am trying to use. But I need them to link the functions for the RTEMS OS itself?

Ben Dart

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20160202/07f5af1b/attachment-0001.html>

More information about the users mailing list