Compile C file on openwrt - compilation

I have built the openwrt firmware and installed it to a device.
Now I want to compile my source code in C in the device (I can ssh into it).
However, openwrt firmware is quite basic and does not include make.
How can I install make/ equivalent to compile my C source code inside the device running openwrt firmware?

OpenWrt is not intended to work as a build server, so you won't find compiler, linker etc. in its root file system. As you mentioned before, you've successfully compiled the firmware. That means you have cross compiler at hand, so you can cross compile your software and then copy it to your system via scp.
Another approach would be to create your own feed, add your software to this feed, so that at the end you'll get an ordinary ipkg package, that you can download and install via web interface. See OpenWrt documentation for more details.

Lots of Cross Compiler are available for host system i.e PC running any Linux OS.
Just install compiler corresponding to Architecture in which Openwrt is running,
e.g If OpenWRT running on ARM architecture,
sudo apt-get install gcc-arm-linux-gnueabi
then compile source code as:
arm-linux-gcc -o yourprogram yourprogram.c

Related

"apt-get: command not found" issue raspberrry pi os built using Buildroot

I have built a sdcard.img for raspberry pi using Buildroot. When I run apt-get command it throws error "apt-get: command not found". I did not find apt-get/dpkg package to enable in 'make menuconfig' options. Now I'm trying to run cross-compiled opencv program on my Rpi but some shared libraries are missing and I want to install these libraries using apt repository (as I already did it on standard Raspbian Stretch os & program run successfully).
I googled it, there's no solution for Buildroot rasbpbian os. Also I tried downloading and installing .deb packages for apt/apt-get/dpkg, didn't work.
apt-get: command not found
I want to cross-compile a kernel which will have all the necessary packages such as apt/dpkg, bin and lib files. Or for the time being to get the work done need guidance to install apt/dpkg packages on Rpi buildroot os.
Buildroot will never have apt or any package manager. With buildroot you have to decide ahead-of-time what packages you'll want included in your rootfs. Use Raspbian if you want to use apt-get.
robert-orr has already answered your question but I think you are confused about the naming. You cannot rebuild raspbian using buildroot.
Rebuilding raspbian (a debian derivative) is a fairly involved process. You have to implement bootstrapping of a distro (compile a compiler, compile your packages with your compiled compiler, etc.) See Debian Bootstrap for everything needed to create your own distro from source. This is usually done by debian and debian-derivative distributions only.
You can build a simpler image using Buildroot, if that satisfies your needs. Also look at Yocto/OE to see if that satisfies your requirement for building an image from source.
With a Buildroot-generated system, it is not possible to use a package manager, because there is no way to make sure the package binaries will actually work on your system. There are two reasons for this:
Binaries depend on the toolchain (C library, kernel header version, subarchitecture choices, ABI choices). There are hundreds of combinations of these choices possible in Buildroot, it's not possible to build package binaries for all of them. Traditional distros limit the choices to just one per architecture.
How one package is configured affects how other packages can be built. Again, Buildroot offers choices there, while traditional distros choose one (usually enable all features).
In Buildroot, instead of using apt-get, you'd go back to make menuconfig, select the additional packages you want to install, and rebuild the system.

How to cross compile from Mac to Linux?

I wrote a little game using Rust, and I used cargo build --release to compile a release version on Mac.
I tried to share this with my friend who is using Ubuntu, but when he tried to run the binary, he got the following error:
cannot execute binary file: Exec format error
I searched for this but found no answers. Doesn't Rust claim to have "no runtime"? Shouldn't it be able to run anywhere in binary form?
Rust not having a runtime means that it doesn't have a lot of code running as part of the language (for example a garbage collector or bytecode interpreter). It does still need to use operating system primitives (i.e. syscalls), and these are different on MacOS and Linux.
What you want is a cross compiler. If you're using rustup, then installing a cross compiler should be simple:
# Install the toolchain to build Linux x86_64 binaries
rustup target add x86_64-unknown-linux-gnu
Then building is:
cargo build --release --target=x86_64-unknown-linux-gnu
Caveat: I don't have an OS X machine to test this on; please comment or edit to fix this if it works!
Well, it is because Rust has no runtime (unlike e.g. Java's JVM) that you can't just compile code on one OS and expect it to run on a different one; what you are looking for is cross-compilation. I haven't done it in Rust, but from what I can gather you can find relevant information on different cross-compilation Rust strategies on this GitHub repo.

Compiling Geary for Windows

I would like to compile the Linux-based mail client, Geary, for my Windows computer.
I'm wondering if I could compile it using a program such as MonoDevelop on my Linux machine with the target being Windows, or if I'll have to use cygwin or mingw on my Windows machine.
Thanks
You can cross compile on Linux to Windows. There is a MinGW build for Linux. Use valac -C to produce C sources then i586-mingw32msvc-gcc to compile the sources and link against Windows DLLs of the libraries needed. Vala determines includes using pkg-config which will pick up compilation arguments from the host system. You can override this by setting PKGCONFIG_PATH to the directories where your Windows libraries' .pc files live.
Alternatively to compiling, you can run Geary on Windows 10 via the WSL.
This question here lead to give it a try. It can be done, but requires many steps and it doesn’t work very well for the time being.
https://heracl.es/ephemera/2018/08/08/geary/
Do you really need to compile it? If you have windows 10, you can run a linux environment, for instance ubuntu. Then Geary runs. I can confirm, as I have it running NOW.
There are several tutorials on how to get Ubuntu running in the WSL on Win10.

how to build linux kernel in OpenWrt distribution

I make a modification in linux kernel of OpenWrt and then I compile the new (kernel) with command :
make target/linux/compile V=99
but I don't found the new image under
build_dir\linux-x86_generic\linux-3.3.8
in order to upgrade the kernel in my OpenWrt running in VM VirtuaBox
how to proceed to get the new kernel and upgrade the Openwrt ?
I am a bit puzzled by the fact you are looking at the linux-x86 folder since with openWRT you usually cross-compile everytime, or at least I've never used it for not cross compilations.
What are you compiling for ?
You should see a build/$TARGET folder with a linux-x-x directory in it where the linux kernel was compiled.

How can I setup linux to compile FORTRAN code into windows binaries?

I'm working on a FORTRAN project and I would like to build all of the binaries that I want to maintain on a linux machine that is dedicated for automated builds. I have successfully used mingw to build 32-bit and 64-bit binaries from C source for windows machines on the linux machine with the following packages on Ubuntu.
apt-get install mingw32
apt-get install mingw-w64
Then I run the following commands to actually compile:
gcc -b amd64-mingw32msvc -V 4.4.4 -o <...other options>
However, the mingw packages that I've obtained via apt-get do not include FORTRAN compilers.
Anybody got any ideas on what I can do?
if you got mingw32 and the Gnu C cross compiler is working for you ... when why not just get the Gnu Fortran cross compiler, too?
http://www.nber.org/sys-admin/mingw32-fortran-fedora.html
EXAMPLE apt-get install mingw32-gcc-fortran
I know this is an old thread but a few things seem to have changed and people might still be interested in the topic.
Problem: I want to use my linux machine to compile some code and create a .exe that I can send to people using Windows.
Solution: Essentially here: http ://mxe.cc/
What I did:
Check to see if your system has all the software you need here
run
git clone -b stable https://github.com/mxe/mxe.git
It will download a few small things and create the directory "mxe" (probably in your home folder)
cd into that mxe directory and run "make". HOWEVER: this would take hours and take up a few GB on your hard drive so instead run something like
make mpfr eigen opencsg cgal qt
For more ideas on how to shorten that all see this or the mxe tutorial or somewhere else ;)
The easiest way to compile stuff then seems to be something like:
~/mxe/usr/bin/i686-pc-mingw32-gfortran -c main.f95
~/mxe/usr/bin/i686-pc-mingw32-gfortran main.o -o outfile.exe
Of course you can chose something other than fortran, just consult the mxe/usr/bin to see what its called.
You can always download and install a prebuilt compiler from the MinGW(-w64) project itself:
Windows 64-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/4.6.2-1/
Windows 32-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/4.6.2-1/
Just unpack somewhere and add the cross*/bin directory to PATH.
I include (obj)c(++) and fortran.
On Ubuntu 18.04 I use
apt install gfortran-mingw-w64
Then use the compiler x86_64-w64-mingw32-gfortran in place of gfortran. If you're using cmake, you can configure the compiler from the build directory like so:
FC=x86_64-w64-mingw32-gfortran cmake ..

Resources