Archive
[Nim] cross-compile under Linux to Windows
Problem
You are under Linux, and you can produce an executable binary with the Nim compiler. However, you would like to produce a Windows EXE too. We want to stay under Linux and we want to produce the EXE on Linux. How to do that?
Solution
On Manjaro, I had to install this package:
$ yaourt -S mingw-w64-gcc-bin
It’s a cross-compiler that we’ll use for producing the EXE.
Let’s take a simple Nim source (hello.nim
):
echo "hello windows"
Now cross-compile it:
$ nim --os:windows --cpu:amd64 --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release c hello.nim
And you get hello.exe
.
$ file hello.exe hello.exe: PE32+ executable (console) x86-64, for MS Windows
If you copy it on a Windows system, you can run it there without any problem. Or, you can also run it under Linux with wine :)
$ wine hello.exe hello windows
Credits
I found this idea in the following blog post: Writing a 2D Platform Game in Nim with SDL2.
Update (20181028)
I found info about it in the official docs too: https://nim-lang.github.io/Nim/nimc.html#cross-compilation-for-windows.
compile and try a Go project on GitHub
Problem
I found an interesting Go project on GitHub (https://github.com/ichinaski/pxl) that I wanted to try. How to compile it?
(This project “pxl” can display images in the terminal).
Solution
GOBIN=$(pwd) GOPATH=/tmp/gobuild go get github.com/ichinaski/pxl
Under Manjaro I had to install the package “gc”, which contains the official Go compiler.
upgrade tmux to the latest version
What I love in Manjaro is that it contains the latest software versions. For instance, I installed tmux and on Manjaro it’s version 2.1.
On Ubuntu 14.04 it’s still version 1.8 in the reposotories…
Problem
How to upgrade tmux 1.8 to 2.1 on Ubuntu?
Solution
Install these packages:
$ sudo apt-get install exuberant-ctags cmake libevent-dev libncurses5-dev
Then download the source of tmux from the official home page. Then build and install:
$ ./configure && make $ sudo make install
This tip is from here.
[manjaro] speed up the compilation of AUR packages
Problem
When compiling AUR packages, only one core is used. How to use more cores and speed up the compilation?
Solution
I found this tip here.
Edit the file “/etc/makepkg.conf” and modify this line:
MAKEFLAGS="-j$(nproc)"
It will use all your cores. Or, you can specify how many cores to use:
MAKEFLAGS="-j2"
Now two cores will be used for the compilation.
Wandbox: a social compilation service
Wandbox is a project that allows you to try several languages in your browser. Just paste the code and Wandbox will compile/interpret it and show you the result.
Try it here. The source code is on GitHub.
The service can be called via an API too! The API doc. is here: https://github.com/melpon/wandbox/blob/master/kennel/API.rst.
Install Midnight Commander from source
This post is deprecated. Repositories nowadays contain a modern version of Midnight Commander, so it’s not necessary anymore to install it from source.
Problem
I’ve already noticed that the Ubuntu repositories are sometimes very out-of-date. A good example for this is the “mc” package. There is a PPA for Midnight Commander that should solve this problem but it’s also very old. At the time of writing (August 10, 2011), the current stable release is 4.7.5.3 while the PPA contains the version 4.7.0.9 (updated on Sept. 15, 2010).
Solution
Since I wanted to use a fresh release of MC, I installed it from source. Steps to follow:
- Download the latest stable source and unpack it.
- For a successful compilation I had to install this package too: “sudo apt-get install libslang2-dev libglib2.0-dev”.
./configure
make
- If it was successful then you should have a binary “
mc
” file in thesrc/
folder. If it’s there, you can remove your current version with “sudo apt-get remove mc
“. - Then install the new version with “
sudo make install
“.
I also had to modify my .bashrc
a bit:
# old: #alias mc='. /usr/share/mc/bin/mc-wrapper.sh' # new: alias mc='. /usr/local/libexec/mc/mc-wrapper.sh'
Update (20120505)
Installing mc from source is now integrated in jabbatron.
Convert PDF to EPS
Problem
I wanted to submit a paper but they required the LaTeX source too, including the images. They accepted EPS images but not PDF! WTF? All my images are in PDF format. How to convert them to EPS?
Solution
pdftops -eps file.pdf
This tip is from here.
Appendix
Here I had another difficulty: EPS images are not supported by pdflatex
. Great! So I had to switch back to the old latex
command…
Compilation with pdflatex:
#!/bin/bash MAIN=main.tex pdflatex $MAIN.tex bibtex $MAIN pdflatex $MAIN.tex pdflatex $MAIN.tex \rm *.aux *.blg *.dvi *.log *.bbl *.flg *.idx *.ind *.lof *.lot *.toc *.glo *.gls *.ilg 2>/dev/null
Compilation with latex:
#!/bin/bash MAIN=main.tex LATEX=latex $LATEX $MAIN.tex bibtex $MAIN $LATEX $MAIN.tex $LATEX $MAIN.tex dvips $MAIN.dvi -o $MAIN.ps ps2pdf $MAIN.ps \rm $MAIN.ps *.aux *.blg *.dvi *.log *.bbl *.flg *.idx *.ind *.lof *.lot *.toc *.glo *.gls *.ilg 2>/dev/null