Linking Shared/Static library in Freeradius Module

Mustafa Reşit Şahin resitsahin at gmail.com
Thu Dec 8 15:19:31 CET 2011


Hello,

I will try to explain what i am trying to achive.

I am developing a freeradius module called rlm_itap. This module uses a 
shared library called print.so (a library i use for test purposes.). 
There is only one procedure in the library and it is called : myprint() 
. I am able to run freeradius server with my own module :

$ radiusd -X

I send a test message with

$ radtest testuser "pass" localhost 0  testing123


If i do not use myprint() function in my own module everything works 
fine and  i am able to receive the incomming message:

+- entering group authorize {...}
++[preprocess] returns ok
ITAP: Received auth message                  =>*My own debug msg*

But when i use the method myprint() from the library print.so , i get 
the error when i run the server and send a message with radtest :

/# Executing section authorize from file 
/usr/local/etc/raddb/sites-enabled/default
+- entering group authorize {...}
++[preprocess] returns ok
ITAP: Received auth message
/libexec/ld-elf.so.1: 
/usr/local/lib/freeradius-2.1.10/rlm_itap-2.1.10.so: *Undefined symbol 
"myprint"*/



So this is the problem i am having. After your email i started to use 
autoconf and it is easier than writing my own makefile. But i am still 
not able to resolve this problem. As far as i understand freeradius is 
not able to see find print.so library. I have to find a way to show the 
server this library....

I prepare my module as :

$ autoconf
$ ./configure
$ gmake clean
$ gmake
$ gmake install


Here is some more information and my makefiles:


*$ gmake *

[root at vm1 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap]# 
gmake
for x in .libs/* rlm_itap.la; do \
         rm -rf 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/lib/$x; 
\
         ln -s 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap/$x 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/lib/$x; 
\
     done
[root at vm1 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap]# 
gmake clean
[root at vm1 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap]# 
gmake
/usr/local/bin/libtool --mode=compile cc  -O2 -pipe -I/usr/local/include 
-L/usr/local/lib -DHAVE_LT_DLADVISE_INIT -DHAVE_LT_DLADVISE_INIT 
-fno-strict-aliasing -pthread -Wall -D_GNU_SOURCE -DNDEBUG 
-I/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src  
-I/usr/include -I/home/resit/radius/include/ -c rlm_itap.c
libtool: compile:  cc -O2 -pipe -I/usr/local/include -L/usr/local/lib 
-DHAVE_LT_DLADVISE_INIT -DHAVE_LT_DLADVISE_INIT -fno-strict-aliasing 
-pthread -Wall -D_GNU_SOURCE -DNDEBUG 
-I/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src 
-I/usr/include -I/home/resit/radius/include/ -c rlm_itap.c  -fPIC -DPIC 
-o .libs/rlm_itap.o
libtool: compile:  cc -O2 -pipe -I/usr/local/include -L/usr/local/lib 
-DHAVE_LT_DLADVISE_INIT -DHAVE_LT_DLADVISE_INIT -fno-strict-aliasing 
-pthread -Wall -D_GNU_SOURCE -DNDEBUG 
-I/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src 
-I/usr/include -I/home/resit/radius/include/ -c rlm_itap.c -o rlm_itap.o 
 >/dev/null 2>&1
/usr/local/bin/libtool --mode=link cc -release 2.1.10 \
     -module -export-dynamic -rpath=/usr/lib:/usr/local/lib  -o 
rlm_itap.la     \
     -rpath /usr/local/lib/freeradius-2.1.10 rlm_itap.lo rlm_itap.c 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/lib/libfreeradius-radius.la 
-lc -L/home/resit/radius/lib/ /home/resit/radius/lib/print.so
libtool: link: cc -shared  .libs/rlm_itap.o   -Wl,-rpath 
-Wl,/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/lib/.libs 
-Wl,-rpath -Wl,/usr/local/lib/freeradius-2.1.10 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/lib/.libs/libfreeradius-radius.so 
-L/usr/local/lib -pthread -L/home/resit/radius/lib/  -pthread   -pthread 
-Wl,-soname -Wl,rlm_itap-2.1.10.so -o .libs/rlm_itap-2.1.10.so
libtool: link: (cd ".libs" && rm -f "rlm_itap.so" && ln -s 
"rlm_itap-2.1.10.so" "rlm_itap.so")
libtool: link: ar cru .libs/rlm_itap.a  rlm_itap.o
libtool: link: ranlib .libs/rlm_itap.a
libtool: link: ( cd ".libs" && rm -f "rlm_itap.la" && ln -s 
"../rlm_itap.la" "rlm_itap.la" )
for x in .libs/* rlm_itap.la; do \
         rm -rf 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/lib/$x; 
\
         ln -s 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap/$x 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/lib/$x; 
\
     done






*$ gmake install :

*[root at vm1 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap]# 
gmake install
gmake[1]: Entering directory 
`/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap'
touch .
gmake[1]: Leaving directory 
`/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap'
if [ "xrlm_itap" != "x" ]; then \
         /usr/local/bin/libtool --mode=install 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/install-sh -c -c \
         rlm_itap.la /usr/local/lib/freeradius-2.1.10/rlm_itap.la || 
exit $?; \
         rm -f /usr/local/lib/freeradius-2.1.10/rlm_itap-2.1.10.la; \
         ln -s rlm_itap.la 
/usr/local/lib/freeradius-2.1.10/rlm_itap-2.1.10.la || exit $?; \
     fi
libtool: install: warning: relinking `rlm_itap.la'
libtool: install: (cd 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/modules/rlm_itap; 
/bin/sh /usr/local/bin/libtool  --mode=relink cc -release 2.1.10 -module 
-export-dynamic -rpath=/usr/lib:/usr/local/lib -o rlm_itap.la -rpath 
/usr/local/lib/freeradius-2.1.10 rlm_itap.lo rlm_itap.c 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/src/lib/libfreeradius-radius.la 
-lc -L/home/resit/radius/lib/ /home/resit/radius/lib/print.so )
libtool: relink: cc -shared  .libs/rlm_itap.o   -Wl,-rpath 
-Wl,/usr/local/lib/freeradius-2.1.10 -L/usr/local/lib/freeradius-2.1.10 
-lfreeradius-radius -L/usr/local/lib -pthread -L/home/resit/radius/lib/  
-pthread   -pthread -Wl,-soname -Wl,rlm_itap-2.1.10.so -o 
.libs/rlm_itap-2.1.10.so
libtool: install: 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/install-sh -c 
-c .libs/rlm_itap-2.1.10.soT 
/usr/local/lib/freeradius-2.1.10/rlm_itap-2.1.10.so
libtool: install: (cd /usr/local/lib/freeradius-2.1.10 && { ln -s -f 
rlm_itap-2.1.10.so rlm_itap.so || { rm -f rlm_itap.so && ln -s 
rlm_itap-2.1.10.so rlm_itap.so; }; })
libtool: install: 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/install-sh -c 
-c .libs/rlm_itap.lai /usr/local/lib/freeradius-2.1.10/rlm_itap.la
libtool: install: 
/usr/ports/net/freeradius2/work/freeradius-server-2.1.10/install-sh -c 
-c .libs/rlm_itap.a /usr/local/lib/freeradius-2.1.10/rlm_itap.a
libtool: install: chmod 644 /usr/local/lib/freeradius-2.1.10/rlm_itap.a
libtool: install: ranlib /usr/local/lib/freeradius-2.1.10/rlm_itap.a
----------------------------------------------------------------------
Libraries have been installed in:
    /usr/local/lib/freeradius-2.1.10

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
      during execution
    - add LIBDIR to the `LD_RUN_PATH' environment variable
      during linking
    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------





[root at vm1 /usr/local/lib/freeradius-2.1.10]# *nm rlm_itap-2.1.10.so*
00000000001011c0 A _DYNAMIC
00000000001013a8 A _GLOBAL_OFFSET_TABLE_
                  w _Jv_RegisterClasses
0000000000101388 d __CTOR_END__
0000000000101380 d __CTOR_LIST__
0000000000101398 d __DTOR_END__
0000000000101390 d __DTOR_LIST__
00000000001011b8 r __FRAME_END__
00000000001013a0 d __JCR_END__
00000000001013a0 d __JCR_LIST__
0000000000101408 A __bss_start
                  w __cxa_finalize@@FBSD_1.0
0000000000000b80 t __do_global_ctors_aux
0000000000000a00 t __do_global_dtors_aux
0000000000101000 d __dso_handle
0000000000101408 A _edata
0000000000101410 A _end
0000000000000bb8 T _fini
0000000000000970 T _init
                  U cf_section_parse
0000000000101408 b completed.5133
                  U debug_flag
0000000000000a50 t frame_dummy
                  U free@@FBSD_1.0
0000000000000aa0 t itap_accounting
0000000000000a80 t itap_authenticate
0000000000000ac0 t itap_authorize
0000000000000ab0 t itap_checksimul
0000000000000af0 t itap_detach
0000000000000b00 t itap_instantiate
0000000000000a90 t itap_preacct
                  U log_debug
00000000001010a0 d module_config
                  U myprint
0000000000101008 d p.5131
                  U rad_malloc
0000000000000c7f r rcsid
0000000000000c57 r rcsid_conffile_h
0000000000000c52 r rcsid_event_h
0000000000000c66 r rcsid_hash_h
0000000000000c75 r rcsid_libradius_h
0000000000000c61 r rcsid_md4_h
0000000000000c70 r rcsid_missing_h
0000000000000c43 r rcsid_modules_h
0000000000000c5c r rcsid_packet_h
0000000000000c7a r rcsid_radiusd_h
0000000000000c48 r rcsid_realms_h
0000000000000c4d r rcsid_stats_h
0000000000000c6b r rcsid_token_h
0000000000101020 D rlm_itap



[root at vm1 /usr/local/lib/freeradius-2.1.10]# *ldd rlm_itap-2.1.10.so*
rlm_itap-2.1.10.so:
     libfreeradius-radius-2.1.10.so => 
/usr/local/lib/freeradius-2.1.10/libfreeradius-radius-2.1.10.so 
(0x800c00000)
     libthr.so.3 => /lib/libthr.so.3 (0x800d21000)
     libc.so.7 => /lib/libc.so.7 (0x800647000)


[root at vm1 /usr/local/lib/freeradius-2.1.10]#*ldd 
libfreeradius-radius-2.1.10.so *
libfreeradius-radius-2.1.10.so:
     libthr.so.3 => /lib/libthr.so.3 (0x800c00000)
     libc.so.7 => /lib/libc.so.7 (0x800647000)



*My makefile.in file*

  #######################################################################
TARGET      = @targetname@
SRCS        = rlm_itap.c
HEADERS     = icc-wrapper.h print.h
RLM_CFLAGS  = @itap_cflags@ -I/home/resit/radius/include/
RLM_LIBS    = @itap_ldflags@ -L/home/resit/radius/lib/ 
/home/resit/radius/lib/print.so
RLM_INSTALL = install-itap

## this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.
include ../rules.mak

$(LT_OBJS): $(HEADERS)

## the rule that RLM_INSTALL tells the parent rules.mak to use.
install-itap:
     touch .


*my makefile :*

#######################################################################
TARGET      = rlm_itap
SRCS        = rlm_itap.c
HEADERS     = icc-wrapper.h print.h
RLM_CFLAGS  =  -I/usr/include -I/home/resit/radius/include/
RLM_LIBS    =  -lc -L/home/resit/radius/lib/ /home/resit/radius/lib/print.so
RLM_INSTALL = install-itap

## this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.
include ../rules.mak

$(LT_OBJS): $(HEADERS)

## the rule that RLM_INSTALL tells the parent rules.mak to use.
install-itap:
     touch .


*my configure.in file:
*

AC_PREREQ([2.53])
AC_INIT(rlm_itap.c) # change 'itap'
AC_REVISION($Revision$)
AC_DEFUN(modname,[rlm_itap]) # change 'itap'

if test x$with_[]modname != xno; then

     AC_PROG_CC
     AC_PROG_CPP

     dnl put configuration checks here.
     dnl set $fail to what's missing, on fatal errors.
     dnl use AC_MSG_WARN() on important messages.
     AC_CHECK_LIB(c, printf,
         [ itap_ldflags="$itap_ldflags -lc" ],
         [ fail=$fail" printf" ]
     )

     AC_CHECK_HEADER(stdio.h,
         [ itap_cflags="$itap_cflags -I/usr/include" ],
         [ fail=$fail" stdio.h" ]
     )

     AC_CHECK_HEADERS(stdio.h stdlib.h)  # for the config.h defs
     AC_CHECK_FUNCS(printf)  # for the config.h defs

     targetname=modname     # keep this!  Don't change!
else
     targetname=            # keep this!  Don't change!
     echo \*\*\* module modname is disabled.  # keep this!  Don't change!
fi

dnl  Don't change this section.
if test x"$fail" != x""; then
     if test x"${enable_strict_dependencies}" = x"yes"; then
         AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
     else
         AC_MSG_WARN([silently not building ]modname[.])
         AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
         targetname=""
     fi
fi


AC_SUBST(itap_cflags)  # change 'itap'
AC_SUBST(itap_ldflags)  # change 'itap'

AC_CONFIG_HEADER(config.h)  # delete if you don't want a config.h file.

AC_SUBST(targetname)  # keep this!  Don't change!
AC_OUTPUT(Makefile)  # keep this!  Don't change!



On 12/07/2011 04:55 PM, Alan DeKok wrote:
> Mustafa Reşit Şahin wrote:
>> Which file mentioned with "These definitions are also # echoed into
>> another file in ../lib," ?
>    Files automatically produced by the builds.
>
>> I could not find this file. As far as i understand, i have to add
>> shared/static libraries ( which i link from my new module ) into this
>> file . So freeradius can find them.
>    No.  You just add them in the RLM_LIBS line.
>
>> I consider this because i get the error :
>>
>> /libexec/ld-elf.so.1:
>> /usr/local/lib/freeradius-2.1.10/rlm_itap-2.1.10.so: Undefined symbol
>> "sendiccmsg"
>>
>> when i run radiusserver and send an autorization message to server.
>    You probably need to re-build radiusd, too.
>
>    Or... *show* what you did.  This isn't hard.
>
>    The current build process *can* link to static libraries, and *does*
> link to static libraries, and *works* when modules are linked to static
> libraries.  If you follow the examples, it *should* work.
>
>    Alan DeKok.
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


-- 
Mustafa Reşit Şahin
Endersys İş Tel: 0216 470 94 23 Dahili:306
Cep Tel:0507 707 68 12

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeradius.org/pipermail/freeradius-users/attachments/20111208/460bc0d8/attachment.html>


More information about the Freeradius-Users mailing list