### Archive

Posts Tagged ‘compile’

## Using sqrt in C lang.

Problem
The following code compiles with “gcc in.c“:

#include
#include

int main()
{
double result = sqrt(9.0);
printf("%lf\n", result);

return 0;
}


The following code drops an error if you try to compile with “gcc in2.c“:

#include
#include

int main()
{
double value = 9.0;
double result = sqrt(value);
printf("%lf\n", result);

return 0;
}


The error message says: “undefined reference to sqrt'”.

Solution and Explanation
In the second case, compile it with “gcc -lm in2.c“, which links the math library. But why does the first example work? In that case the compiler figures out (knows) the value of the square root operation and replaces the function call with a constant 3.0 value. The optimizer is that clever :) In the second case however it tries to call the sqrt() function but it’s not found. If you link the math library, it’ll find it.

## [Nim] cross-compile under Linux to Windows

October 23, 2018 1 comment

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. Categories: bash Tags: , , ## upgrade tmux to the latest version March 17, 2016 Leave a comment 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


$./configure && make$ sudo make install


This tip is from here.

Categories: bash, ubuntu Tags: , ,

## [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. Categories: manjaro Tags: , ## Wandbox: a social compilation service July 30, 2014 1 comment 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 August 10, 2011 6 comments 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 the src/ 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. Categories: bash, ubuntu Tags: , , , ## Convert PDF to EPS July 13, 2011 Leave a comment 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

Categories: latex

## Compile Truecrypt from source

Problem

You want to compile Truecrypt from source but suddenly you realize that it’s not that trivial.

Solution

Let’s install some necessary packages:

sudo apt-get install build-essential libfuse-dev libgtk2.0-dev
sudo apt-get install nasm
sudo apt-get install libwxgtk2.8-dev
# This last one is for the problem "'wx/wx.h' is not found".


Download the source code of Truecrypt (link) and extract it to a folder. I put mine here: /opt/truecrypt-7.0a-source.

From the README of Truecrypt, we need this too: “RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki) 2.20 header files (available at ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20) located in a standard include path or in a directory defined by the environment variable ‘PKCS11_INC’.

So, visit ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20 and download the .h files. Actually, you only need 3 of them; I collected their URLs here. I put these files in this directory: /opt/truecrypt-7.0a-source/PKCS11_INC. Then, register it in an environment variable:

export PKCS11_INC=/opt/truecrypt-7.0a-source/PKCS11_INC

Now you can try to compile it. Go to /opt/truecrypt-7.0a-source and execute the command make. The executable will be placed here: Main/truecrypt.

Optional

I’m not sure that this step is necessary. If you have problems compiling the source, follow these instructions too.

For a successful compilation, you might need the wxWidgets library too. Download the latest stable release (choose wxAll in the list). Mine is extracted here: /opt/wxWidgets-2.8.12.

Get Truecrypt to compile wxWidgets for you:

export WX_ROOT=/opt/wxWidgets-2.8.12/
make WX_ROOT=/opt/wxWidgets-2.8.12 wxbuild


It will create the directory /opt/truecrypt-7.0a-source/wxrelease.

Further help

Remove the binary package

If you installed Truecrypt with the binary .deb package, here is how to remove it:

sudo truecrypt-uninstall.sh

Categories: security Tags: ,

## Install ncurses

sudo apt-get install libncurses5-dev libncursesw5-dev
`