Cross compiling libtins for OpenWRT

915 views
Skip to first unread message

Ralph Das

unread,
Mar 4, 2013, 11:19:15 AM3/4/13
to lib...@googlegroups.com
Hey Mathias,
Let me first say that I really appreciate your library and efforts. I really need a packet analyzer like libtins. I recently started development on a project that runs on OpenWRT.I would really like to use your library and gave it a shot to try to cross-compile it.  

Do you anyone who has already done this and if not, do you think this is possible/ feasible. 

With kind reagards,

Ralph

Matias Fontanini

unread,
Mar 4, 2013, 11:43:05 AM3/4/13
to lib...@googlegroups.com
Hi Ralph,

first of all, thank you for showing interest in the project! I've successfully cross-compiled the library for both MIPS and ARM, so I don't think there should be any problem with cross-compiling it for OpenWRT(assuming you're planning to use any of those architectures, which I believe are the most common).

As long as you've got the proper build toolchain and provide the right flags when executing the configure/Makefile script(such as CROSS_COMPILE and ARCH), you should be fine.

In case you don't know how to proceed, I'd be glad to help you.

Cheers,
Matias

Ralph Das

unread,
Mar 6, 2013, 5:18:39 AM3/6/13
to lib...@googlegroups.com
Hey Mattias,
Thanks for you answer! Yes I would like some assistance since I'm pretty new to cross-compiling (manual at least). I have set up a working OpenWRT toolchain and i'm working with libpcap at the moment to capture some WIFI frames. I encounter a lot of issues which are already dealt with by libtins (endianess, radiotap parsing etc.) Maybe I can incorporate your instructions in the form a small step by step 'howto' tutorial for future reference . Maybe later I can try to put it into a standard OPKG package for others to use. 

At the moment i'm compiling my program through the Eclipse IDE using the cross compiler. Looking forward to your response.

Ralph

Matias Fontanini

unread,
Mar 6, 2013, 3:03:28 PM3/6/13
to lib...@googlegroups.com
Hello,

I don't have an OpenWRT toolchain yet. You could try the following, if
it doesn't work for you, then I'll download and compile the toolchain so
I can test it. Cross-compiling should be the same, no matter which
platform you're targetting.

I've just tried compiling for ARM, using an ARM toolchain I already
have, and it worked. Let's suppose you've got your toolchain in this
path(examples using my ARM toolchain):

/opt/arm_linux_toolchain/

Let's assume that directory is called TOOLCHAIN_DIR. That directory
contains the following subdirectories:

arm-linux bin distributed info libexec tmp
arm-linux.crosstoolconfig.txt COPYING include lib man

Inside the "bin" subdirectory, you've got the compilers, linkers,
debuggers and other utilities:

arm-linux-addr2line arm-linux-g++ arm-linux-ld arm-linux-size
arm-linux-gcc arm-linux-nm arm-linux-strings
.....

I've also cross-compiled libpcap; the header files are located in
$TOOLCHAIN_DIR/include and the shared objects are stored in
$TOOLCHAIN_DIR/lib.

So now, all I had to do is issue the following command:

LD=/opt/arm_linux_toolchain/bin/arm-linux-ld \
CXX=/opt/arm_linux_toolchain/bin/arm-linux-g++ \
./configure --with-pcap-include-path=/opt/arm_linux_toolchain/include/ \
--with-pcap-lib-path=/opt/arm_linux_toolchain/lib/

Where:
LD indicates the path to the linker you're going to use.
CXX indicates the path to the C++ compiler you're going to use.
--with-pcap-include-path indicates the path in which you're storing the
pcap header files.
--with-pcap-lib-path indicates the path in which you're storing the pcap
shared objects(libpcap.so.whatever)

Once that script finishes running, you should execute "make" as usual.

Note that you don't have to provide an absolute path for the compiler
and linker if they're installed in one of the paths listed in the
environment variable PATH(this was not true for me).

According to what's mentioned here
http://wiki.openwrt.org/doc/devel/crosscompile the compiler and linker
will be stored inside your toolchain directory and their names will
follow this format:

ARCHITECTURE-openwrt-linux-uclibc-g++
ARCHITECTURE-openwrt-linux-uclibc-ld

Where ARCHITECTURE would probably be "arm" in my example.

If you're using eclipse, then you should do the exact same thing through
the GUI: specify the C++ cross-compiler, the linker, the libpcap include
directory, and the pcap shared objects path.

I hope this helps you. I'm going to add an explanation about how to
cross-compile the library in the libtins website soon.

Cheers,
Matias

Ralph Das

unread,
Mar 11, 2013, 7:22:53 AM3/11/13
to lib...@googlegroups.com
Hey Matias,
Thanks for your instructions. I haven't had the time yet to give it a try. But when I'll do I will keep you up to date.

Cheers Ralph

Ralph Das

unread,
Mar 12, 2013, 7:43:30 AM3/12/13
to lib...@googlegroups.com
Hey Matias,
Well I got a whole lot further and I think I'm almost there. The compiler shoots an error on what i suspect is the end of the process. It looks like the compilation wants to generate a .dynlib opossed to a .so and tries to put on some install directory which is at my host computer. This is I think because I use OSX for cross compilation opposed to a decent Linux version. I'm I right about this?

Here is the output generated by the compiler. 


libtool: link: /Volumes/OpenWRT/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++ -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libtins.0.dylib  src/.libs/arp.o src/.libs/bootp.o src/.libs/crypto.o src/.libs/dhcp.o src/.libs/dhcpv6.o src/.libs/dns.o src/.libs/dns_record.o src/.libs/dot11.o src/.libs/eapol.o src/.libs/ethernetII.o src/.libs/icmp.o src/.libs/icmpv6.o src/.libs/ieee802_3.o src/.libs/internals.o src/.libs/ip.o src/.libs/ip_address.o src/.libs/ipv6.o src/.libs/ipv6_address.o src/.libs/llc.o src/.libs/loopback.o src/.libs/network_interface.o src/.libs/packet_sender.o src/.libs/packet_writer.o src/.libs/pdu.o src/.libs/radiotap.o src/.libs/rawpdu.o src/.libs/rsn_information.o src/.libs/sll.o src/.libs/snap.o src/.libs/sniffer.o src/.libs/tcp.o src/.libs/tcp_stream.o src/.libs/udp.o src/.libs/utils.o   -lpcap -L/Volumes/OpenWRT/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib/  -O2 -O3   -install_name  /usr/local/lib/libtins.0.dylib -compatibility_version 1 -current_version 1.3 -Wl,-single_module
mips-openwrt-linux-g++: error: 1: No such file or directory
mips-openwrt-linux-g++: error: 1.3: No such file or directory
mips-openwrt-linux-g++: error: unrecognized option '-compatibility_version'
mips-openwrt-linux-g++: error: unrecognized option '-current_version'
make: *** [libtins.la] Error 1

Or is this caused by the fact that I use the OSX make command?

Let me know.

Greets Ralph

Matias Fontanini

unread,
Mar 12, 2013, 8:05:51 AM3/12/13
to lib...@googlegroups.com
Mmm, your error should be fixed by removing these options from that
invocation to g++:

-compatibility_version 1 -current_version 1.3

As for the dylib quesion, it might have something to do with the fact
that you're cross-compiling it on OSX. Anyway, the generated file
should be a shared object, no matter what's the extension used. You
might have to rename the resulting file to .so in order to make it
work under OpenWRT though.

Hope this helps.

Cheers,
Matias
> --
> You received this message because you are subscribed to the Google Groups "libtins" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to libtins+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Ralph Das

unread,
Mar 12, 2013, 9:04:42 AM3/12/13
to lib...@googlegroups.com
Hey Mathias,
I removed those lines from the libtool file and came across this:

/Volumes/OpenWRT/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.4/../../../../mips-openwrt-linux-uclibc/bin/ld: bad -rpath option

I checked it but the directory does exist. Any ideas? Otherwise I just switch to Ubuntu.

Greets Ralph

Matias Fontanini

unread,
Mar 12, 2013, 9:19:21 AM3/12/13
to lib...@googlegroups.com
According to what's said in this thread:

http://lists.apple.com/archives/unix-porting/2008/Mar/msg00008.html

You can replace the "-rpath" option with "-install_name" in OSX. Try
doing that and see if it works.

Cheers

Ralph Das

unread,
Mar 12, 2013, 9:31:53 AM3/12/13
to lib...@googlegroups.com
Thanks.. Sort of did the trick. It generated a .a and a .la file in the .libs directory. Now I just need to check if the generated .a file is valid.
Reply all
Reply to author
Forward
0 new messages