C dhcpctl linking error

Glenn Satchell glenn.satchell at uniq.com.au
Thu Dec 13 10:09:44 UTC 2012


Hi

The resulting executable is huge because you have statically linked in all
the dhcp and bind9 libraries. You could try using dynamic libraries which
link in at run time.

Check to see if the shared libraries exist, they will be libdns.so.* eg

ls /usr/lib/libdns* /usr/lib/libisc*

You may need to install the bind9 package to get them.

Change your link command to:

gcc -Wall nnetd.o /usr/local/lib/libdhcpctl.a /usr/local/lib/libomapi.a
/usr/local/lib/libdst.a -L /usr/lib -ldns -lisc -o nnetd

-L /usr/lib says to look in that directory
-lfoo says look for libfoo.so or libfoo.a

so the rather long /usr/local/lib/libdhcpctl.a /usr/local/lib/libomapi.a
/usr/local/lib/libdst.a

could be replaced by: -L /usr/local/lib -ldhcpctl -lomapi -ldst

Now even though the executable is large, most of it will be parts of the
libraries that are not used, so they won't be mapped into memory. Check
using a tool like 'top' and you should see that the resident size is much
smaller than what you might expect.

If you wish, you can remove the symbol table using 'strip', compare sizes
before and after, eg:

ls -l nnetd
strip nnetd
ls -l nnetd

Once the symbol table is removed though you won't get subroutine and
variable names when using a debugger. So this might be an option once you
are confident your program is working as expected.

regards,
-glenn

On Thu, December 13, 2012 8:18 pm, Sztrepka Pál wrote:
> 2012-12-07 10:59 időpontban Sztrepka Pál ezt írta:
>
>> nnetd.c:(.text.startup+0x1a): undefined reference to
>> `dhcpctl_initialize'
>> nnetd.c:(.text.startup+0x46): undefined reference to
>> `dhcpctl_new_authenticator'
>> nnetd.c:(.text.startup+0x6a): undefined reference to
>> `dhcpctl_connect'
>>
>> I compile with this way:
>>    gcc -Wall -O2   -c -o nnetd.o nnetd.c
>>       It's ok, object file is created
>>
>> But, when i try linking whit this command:
>>    gcc -Wall -O2 -ldhcpctl -lomapi -ldst nnetd.o -o nnetd
>>       I get the above error.. :-(
>
> Ok, my solution:
>
> 1. I compile from source (dhcp-4.2.4-P2)
> 2. then I copy from ../dhcpd-4.2.4-P2/bind/lib/ the 'libdns.a' and the
> 'libisc.a' to /usr/local/lib/
>    (libdhcpctl.a, libomapi.a, libdst.a is also created in this lib
> directory after 'make install')
> 3. and I compile and link my C code this method:
>    gcc -Wall -O2 nnetd.o /usr/local/lib/libdhcpctl.a
> /usr/local/lib/libomapi.a /usr/local/lib/libdst.a
> /usr/local/lib/libdns.a /usr/local/lib/libisc.a -o nnetd
>
> I think, this way not so elegant, but my executable (nnetd) is created,
> and working..
> But I dont't understand why this exe so big? ( 4.9MB!! )
> Is there a way to reduce this size?
>
> --
>   Sztrepka Pál
>
> _______________________________________________
> dhcp-users mailing list
> dhcp-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/dhcp-users
>
>




More information about the dhcp-users mailing list