# Cross-compile from Ubuntu

**URL:** <https://forum.openwrt.org/t/cross-compile-from-ubuntu/3271>\
**Category:** For Developers\
**Created:** [April 25, 2017, 9:29am UTC](https://forum.openwrt.org/t/cross-compile-from-ubuntu/3271 "2017-04-25T09:29:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike1](https://forum.openwrt.org/letter_avatar/mike1/32/5_5575768a8748004e209b776fc1b2916d.png) [@mike1](https://forum.openwrt.org/u/mike1)\
**Post date:** [April 25, 2017, 9:29am UTC](https://forum.openwrt.org/t/cross-compile-from-ubuntu/3271/1 "2017-04-25T09:29:09Z")

</div>

Hello, I need to compile a simple custom C program (linked with libusb) for my router (MIPS 24kc, ar71xx target) from an Ubuntu machine. Do I need a special GCC toolchain or the standard GCC will do (then what compiler options to use)?

Also I guess I'll have to link it against the libc library version used on the router, so what is the right way of doing it? Or maybe there is a wiki page describing how to set up a development environment for cross-compiling for the ar71xx target which I haven't found?

Thank you.

---

<div class="post-metadata">

**Author:** ![hnyman](https://forum.openwrt.org/user_avatar/forum.openwrt.org/hnyman/32/19_2.png) [@hnyman](https://forum.openwrt.org/u/hnyman)\
**Post date:** [April 25, 2017, 9:47am UTC](https://forum.openwrt.org/t/cross-compile-from-ubuntu/3271/2 "2017-04-25T09:47:57Z")

</div>

You need a LEDE toolchain with tailored gcc and necessary libraries etc. so that you get the compilation options just right.

Either install the full build environment or use the SDK that enables compiling just single packages.

[https://lede-project.org/docs/guide-developer/install-buildsystem](https://lede-project.org/docs/guide-developer/install-buildsystem)  
[https://lede-project.org/docs/guide-developer/use-buildsystem](https://lede-project.org/docs/guide-developer/use-buildsystem)

[https://lede-project.org/docs/guide-developer/compile\_packages\_for\_lede\_with\_the\_sdk](https://lede-project.org/docs/guide-developer/compile_packages_for_lede_with_the_sdk)

But I think that you need to form a real "package" out of your file, especially as you want libusb.

You might also read these old examples  
(query: [https://www.google.com/search?q=openwrt+sdk+single+c+file](https://www.google.com/search?q=openwrt+sdk+single+c+file) )

[https://www.gargoyle-router.com/old-openwrt-coding.html](https://www.gargoyle-router.com/old-openwrt-coding.html)  
[https://forum.openwrt.org/viewtopic.php?id=44846](https://forum.openwrt.org/viewtopic.php?id=44846)

---

<div class="post-metadata">

**Author:** ![mike1](https://forum.openwrt.org/letter_avatar/mike1/32/5_5575768a8748004e209b776fc1b2916d.png) [@mike1](https://forum.openwrt.org/u/mike1)\
**Post date:** [April 25, 2017, 9:54am UTC](https://forum.openwrt.org/t/cross-compile-from-ubuntu/3271/3 "2017-04-25T09:54:26Z")

</div>

Thanks, this seems to be exactly what I needed!
