<div>Hi folks,</div><div><br></div><div> I am newbie to linux application programming and got a problem of linking standard library 'libnl.so'. Here my test code:</div><div><br></div><div>#include <netlink/netlink.h></div>
<div>#include <netlink/genl/genl.h></div><div>#include <netlink/genl/ctrl.h></div><div><br></div><div>int main() {</div><div> struct nl_handle *sock;</div><div> int family;</div><div><br></div><div> // Allocate a new netlink socket</div>
<div> sock = nl_handle_alloc();</div><div>}</div><div><br></div><div>Then, compile and link my code with libnl:</div><div><br></div><div>$ gcc test.c </div><div>/tmp/ccJh2gSl.o: In function `main':</div><div>test.c:(.text+0x12): undefined reference to `nl_handle_alloc'</div>
<div>collect2: ld returned 1 exit status</div><div><br></div><div>However, the paths of header file and library were included already. still don't know why couldn't compile it??</div><div>$ gcc -v test.c </div><div>
Using built-in specs.</div><div>Target: i486-linux-gnu</div><div>Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu</div>
<div>Thread model: posix</div><div>gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) </div><div>COLLECT_GCC_OPTIONS='-v' '-mtune=generic'</div><div> /usr/lib/gcc/i486-linux-gnu/4.3.3/cc1 -quiet -v test.c -D_FORTIFY_SOURCE=2 -quiet -dumpbase test.c -mtune=generic -auxbase test -version -fstack-protector -o /tmp/ccMicv7a.s</div>
<div>ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"</div><div>ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../i486-linux-gnu/include"</div><div>ignoring nonexistent directory "/usr/include/i486-linux-gnu"</div>
<div>#include "..." search starts here:</div><div>#include <...> search starts here:</div><div> /usr/local/include</div><div> /usr/lib/gcc/i486-linux-gnu/4.3.3/include</div><div> /usr/lib/gcc/i486-linux-gnu/4.3.3/include-fixed</div>
<div> /usr/include</div><div>End of search list.</div><div>GNU C (Ubuntu 4.3.3-5ubuntu4) version 4.3.3 (i486-linux-gnu)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.4.0.</div>
<div>GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128351</div><div>Compiler executable checksum: 0bf5703b57e064ca90b48f4e2c186f4a</div><div>COLLECT_GCC_OPTIONS='-v' '-mtune=generic'</div>
<div> as -V -Qy -o /tmp/cckXhlcm.o /tmp/ccMicv7a.s</div><div>GNU assembler version 2.19.1 (i486-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.19.1</div><div>COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/</div>
<div>LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../:/lib/:/usr/lib/</div>
<div>COLLECT_GCC_OPTIONS='-v' '-mtune=generic'</div><div> /usr/lib/gcc/i486-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib/ld-linux.so.2 -z relro /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.3.3/crtbegin.o -L/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.3.3/../../.. /tmp/cckXhlcm.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-linux-gnu/4.3.3/crtend.o /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crtn.o</div>
<div>/tmp/cckXhlcm.o: In function `main':</div><div>test.c:(.text+0x12): undefined reference to `nl_handle_alloc'</div><div>collect2: ld returned 1 exit status</div><div><br></div><div>Search the header file and library:</div>
<div><br></div><div>$ ls /usr/include/netlink/*</div><div>/usr/include/netlink/addr.h /usr/include/netlink/list.h /usr/include/netlink/object.h</div><div>/usr/include/netlink/attr.h /usr/include/netlink/msg.h /usr/include/netlink/socket.h</div>
<div>/usr/include/netlink/cache-api.h /usr/include/netlink/netlink-compat.h /usr/include/netlink/types.h</div><div>/usr/include/netlink/cache.h /usr/include/netlink/netlink.h /usr/include/netlink/utils.h</div>
<div>/usr/include/netlink/data.h /usr/include/netlink/netlink-kernel.h</div><div>/usr/include/netlink/handlers.h /usr/include/netlink/object-api.h</div><div><br></div><div>/usr/include/netlink/fib_lookup:</div><div>
lookup.h request.h</div><div><br></div><div>/usr/include/netlink/genl:</div><div>ctrl.h family.h genl.h mngt.h</div><div><br></div><div>/usr/include/netlink/route:</div><div>addr.h classifier-modules.h link.h nexthop.h route.h sch</div>
<div>class.h class-modules.h neighbour.h qdisc.h rtnl.h tc.h</div><div>classifier.h cls neightbl.h qdisc-modules.h rule.h</div><div>$ ls /usr/lib/libnl*</div><div>/usr/lib/libnl.so /usr/lib/libnl.so.1 /usr/lib/libnl.so.1.1</div>
<div><br></div><div>$ gcc --version</div><div>gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3</div><div><br></div><div>libnl installation info:</div><div><a href="http://libnl-1.1.so">libnl-1.1.so</a></div><div>libnl-dev</div><div>libnl-doc</div>
<div><br></div><div>OS: ubuntu 9.04</div><div><br></div><div>The header file and library seem to be in the right place but why I can not link the library successfully?? </div><div>Is there any one know where I was wrong or missed? Thanks in advance.</div>
<div><br></div><div>Cuthbert</div><div><br></div><div><br></div>