compiling interview questions

Top 15 compiling interview questions

1068 Jobs openings for compiling

How are packages actually installed via apt-get install?

When using the apt-get install method to install a package onto ubuntu, is there any fundamental difference between obtaining the source code for that package and building it from scratch? Does the apt-get install functionality simply download source and build it on your machine to a specified directory or is there more going on behind the scenes ?

Finally (maybe this has no answer) is one method better than the other? What I am angling at here is does the build it yourself from source code have any advantages or is it better to let apt-get do its thing?

Source: (StackOverflow)

What is "openssl binaries" and "openssl development package"?

Build it using general C development environment with bash, gcc (3 or 4 series), make, etc on a linux machine.

Building pre-requirements are:


1. openssl binaries;
2. openssl development package with include files (on debian package libssl-dev);


Source: (StackOverflow)

Type of code conversion used in Linux executable files

I want to ask that what type of encoding is used to make linux executable files e.g. hexadecemal, binary or anything else. how is it converted ? Is there any way to get back the original code from this executable file?

Here's a bit of code I have:

ELF���������>�����%|�����@�������������������@�8��@���������������������@�������@�����7<�����7<������� ������������������f�����f���������������������� ������[�UPX!L
h�h�8����������?�E�h=��ڊ̓�N�    4���9ISloB�q�w�]ȉ.��,ς��Q䝦����#e��-�N����/�b,���d<��'��-E��6E�s�/�U���ly�V�Y2]"a��S�.�hU�|�S�J�I�2���X}

what is it suppose to mean?

Source: (StackOverflow)

How do I set up ccache?

I want to use ccache to speed up compilation. I came across how do I enable ccache

This is what I have done so far:

$ sudo apt-get install -y ccache
$ dpkg -l ccache
ii  ccache  3.1.6-1   Compiler cache for fast recompilation of C/C++ code
$ whereis ccache
ccache: /usr/bin/ccache /usr/lib/ccache /usr/bin/X11/ccache /usr/share/man/man1/ccache.1.gz

I appended ccache to path by adding to my ~/.bashrc

$ export PATH="/usr/lib/ccache:$PATH"
$ source ~/.bashrc
$ echo $PATH 

The symbolic links looks fine:

$ ll /usr/lib/ccache/
total 76
drwxr-xr-x   2 root root  4096 mai   22 10:48 ./
drwxr-xr-x 253 root root 69632 mai   22 10:48 ../
lrwxrwxrwx   1 root root    16 mai   22 10:48 avr-g++ -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 avr-gcc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 avr-gcc-4.5.3 -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 c++ -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 c89-gcc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 c99-gcc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 cc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 g++ -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 g++-4.6 -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 gcc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 gcc-4.6 -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 x86_64-linux-gnu-g++ -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 x86_64-linux-gnu-g++-4.6 -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 x86_64-linux-gnu-gcc -> ../../bin/ccache*
lrwxrwxrwx   1 root root    16 mai   22 10:48 x86_64-linux-gnu-gcc-4.6 -> ../../bin/ccache*

The link looks good:

$ which g++

$ make
g++ -o affine_euler affine_euler.cpp -O3 -DEIGEN_NO_DEBUG -I/usr/include/eigen3
g++ -o test_eigen test_eigen.cpp -O3 -DEIGEN_NO_DEBUG -I/usr/include/eigen3

But the cache is empty:

$ ccache -s
cache directory                     /home/dell/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
files in cache                         0
cache size                             0 Kbytes
max cache size                       1.0 Gbytes

Where am I wrong ?

Source: (StackOverflow)

Installing packages into local directory?

I'd like to install software packages, similar to apt-get install <foo> but:

  1. Without sudo, and
  2. Into a local directory

The purpose of this exercise is to isolate independent builds in my continuous integration server.

I don't mind compiling from source, if that's what it takes, but obviously I'd prefer the simplest approach possible. I tried apt-get source --compile <foo> as mentioned here but I can't get it working for packages like autoconf. I get the following error:

dpkg-checkbuilddeps: Unmet build dependencies: help2man

I've got help2man compiled in a local directory, but I don't know how to inform apt-get of that. Any ideas?

UPDATE: I found an answer that almost works at http://askubuntu.com/a/350/23678. The problem with chroot is that it requires sudo. The problem with apt-get source is that I don't know how to resolve dependencies. I must say, chroot looks very appealing. Is there an equivalent command that doesn't require sudo?

Source: (StackOverflow)

How to compile C++ source code ("iostream.h not found" error)?

I do not want to discuss about C++ or any programming language!I just want to know what am i doing wrong with linux ubuntu about compiling helloworld.cpp!

I am learning C++ so my steps are:

open hello.cpp in vim and write this

#include <iostream.h>
int main()
    cout << "Hello World!\n";`
    return 0;

So, after that i tried in the terminal this

g++ hello.cpp

AND the output is

hello.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.

What do you suggest? Any useful step by step guide for me?Thanks!

Source: (StackOverflow)

Compile OpenGL Program (Missing GL/gl.h)

I am a complete Linux/Ubuntu noob, so I apologize for any dumb portions of this question or follow up ones.

I am trying to get a program that my software engineering class's group wrote onto my home computer. At school, we have Linux, and it will compile and run fine there. I downloaded VMWare, installed Ubuntu on a virtual machine, and now am trying to get my program to open.

When ever I try to run my make file however, I get an error that says

gcc -I../include -pthread -O1 -c rain.c
In file included from rain.c:19:0:
../include/GL/glfw.h:176:21: fatal error: GL/gl.h: No such file or directory
compilation terminated.
make: *** [rain.o] Error 1

Would anyone happen to know why it can't find this file, when it can on my school computers? And what I'd need to do to download it or get it in the right spot?

Source: (StackOverflow)

cmake fails with "CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found."

jonquil@jonquil-Satellite-L755D:~/Downloads/akonadi-googledata-1.2.0/build$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
CMake Error at /usr/share/cmake-2.8/Modules/FindKDE4.cmake:98 (MESSAGE):
  ERROR: cmake/modules/FindKDE4Internal.cmake not found in
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 2.8)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!

With autotools I get this:

jonquil@jonquil-Satellite-L755D:~/Downloads/akonadi-googledata-1.2.0/build/build$ autoreconf -i -f
Can't exec "libtoolize": No such file or directory at /usr/bin/autoreconf line 196.
Use of uninitialized value in pattern match (m//) at /usr/bin/autoreconf line 196.
autoreconf: `configure.ac' or `configure.in' is required

Source: (StackOverflow)

What are the packages/libraries I should install before compiling Python from source?

Once in a while I need to install a new Ubuntu (I used it both for desktop and servers) and I always forget a couple of libraries I should have installed before compiling, meaning I have to recompile, and it's getting annoying.

So now I want to make a complete list of all library packages to install before compiling Python (and preferably how optional they are).

This is the list I compiled with below help and by digging in setup.py. It is complete for Ubuntu 10.04 and 11.04 at least:

build-essential (obviously)
libz-dev        (also pretty common and essential)
libreadline-dev (or the Python prompt is crap)

For Python 3.2 and later:


More optional:


Ubuntu has no packages for v1.8.5 of the Berkeley database, nor (for obvious reasons) the Sun audio hardware, so the bsddb185 and sunaudiodev modules will still not be built on Ubuntu, but all other modules are built with the above packages installed.


There are in Ubuntu 14.04 even more patches needed for Python 2.6, and 2.7 etc. I would recommend to instead checkout pyenv. It contains a script python-build (located in plugins/python-build/bin). With it you can install arbitrary Python versions like this:

$ ./python-build 2.7.8 /opt/python27

Where 2.7.8 is the version and /opt/python27 is the path it will be installed. Pyenv will download the Python version, apply the necessary patches and configure; make; make install for you.


Python 2.5 and Python 2.6 also needs to have LDFLAGS set on Ubuntu 11.04 and later, to handle the new multi-arch layout:

export LDFLAGS="-L/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"

For Python 2.6, 2.7 and 3.0 you also need to explicitly enable SSL after running the ./configure script and before running make. In Modules/Setup there are lines like this:

#_ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl -lcrypto

Uncomment these lines and change the SSL variable to /usr:

_ssl _ssl.c \
       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
       -L$(SSL)/lib -lssl -lcrypto

Python 2.6 and 3.0 also needs Modules/_ssl.c modified to be used with OpenSSL 1.0, which is used in Ubuntu 11.10. At around line 300 you'll find this:

    else if (proto_version == PY_SSL_VERSION_SSL3)
        self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL2)
        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL23)
        self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */

Change that into:

    else if (proto_version == PY_SSL_VERSION_SSL3)
        self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL2)
        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL23)
        self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */

This disables SSL_v2 support, which apparently is gone in OpenSSL1.0.

Python 2.4 (yes, I still have some old projects that need 2.4) needs this patch to setup.py:

--- setup.py    2006-10-08 19:41:25.000000000 +0200
+++ setup.py        2012-05-08 14:02:14.325174357 +0200
@@ -269,6 +269,7 @@
         lib_dirs = self.compiler.library_dirs + [
             '/lib64', '/usr/lib64',
             '/lib', '/usr/lib',
+           '/usr/lib/x86_64-linux-gnu'
         inc_dirs = self.compiler.include_dirs + ['/usr/include']
         exts = []
@@ -496,7 +497,8 @@
                 ssl_incs += krb5_h
         ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
-                                      '/usr/contrib/ssl/lib/'
+                                      '/usr/contrib/ssl/lib/',
+                                     'x86_64-linux-gnu'
                                      ] )

         if (ssl_incs is not None and

And it needs to be compiled with:

env CPPFLAGS="-I/usr/lib/x86_64-linux-gnu" LDFLAGS="-L/usr/include/x86_64-linux-gnu"  ./configure --prefix=/opt/python2.4

Source: (StackOverflow)

What's a simple way to recompile the kernel?

I'm interested in compiling a new kernel under Ubuntu 12.04 x86 64 bit.

I found this wiki page which is basically a mirror for this blog and there are a lot of steps (git, etc.) that appear useless to me.

With earlier releases/distros, I used to create a .config file and modify a Makefile if I needed to, then just run make and it's done.

Is there is a simple way to do this under Ubuntu?

Source: (StackOverflow)

How do I install the latest version of node.js?

How do I install node.js in Ubuntu? I've been looking around, and I can't find anything. Is there a Ubuntu package for node.js, or do I have to compile it myself?

Source: (StackOverflow)

Build 32-bit on 64-bit Ubuntu: installing ia32-libs does not include libstdc++

Googled for a while but drawn a blank.

Need to build 32-bit app on 64-bit Ubuntu.

Realise that I need to install ia32-libs. I have done this and apt-get tells me it's already at the latest version.

This link: http://packages.debian.org/squeeze/amd64/ia32-libs/filelist says that libstdc++ should be in /usr/lib32

It's not there!

I have uninstalled, reinstalled (with force) ia32-libs.

Any ideas? How can I get this critter on my box?

Ta, Ben

Source: (StackOverflow)

Can I rebuild a package without recompiling the source?

I am building a new .deb and want to fix lintian errors in the packaging. However, every time I rebuild, the rules file does a 'make clean' and thus starts compiling again.

Is there a way to instruct the build process that I do not want to recompile, that I'm just altering the packaging, and using the last set of binaries will be fine for now?

Source: (StackOverflow)

How (recipe) to build only one kernel module?

I have a bug in a Linux kernel module that causes the stock Ubuntu 14.04 kernel to oops (crash).

That is why I want to edit/patch the source of only that single kernel module to add some extra debug output. The kernel module in question is mvsas and not necessary to boot. For that reason I don't see any need to update any initrd images.

I have read a lot of information (as shown below) and find the setup and build process confusion. I need two recipes:

  1. to setup/configure the build environment once
  2. steps to do after editing any source file of this kernel module (.c and .h) and converting that edit into a new kernel module (.ko)

The sources that have been used are:

Source: (StackOverflow)

How to add libraries path to the ./configure command?

I would like ./configure to link to a library and some include files. My library is stored in /home/foo/sw/lib/ and my files are stored in /home/foo/sw/include.

./configure --help throws out the following:

Some influential environment variables:

  CC           C compiler command
  CFLAGS       C compiler flags
  LDFLAGS      linker flags, e.g. -L<lib dir> if you have libraries in a 
               nonstandard directory <lib dir>
  LIBS         libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS     (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if 
               you have headers in a nonstandard directory <include dir>
  CPP          C preprocessor

I have tried various combinations:

./configure --prefix=/home/foo/sw -I</home/foo/sw/include> -L</home/foo/sw/lib/>
./configure --prefix=/home/foo/sw -I=/home/foo/sw/include -L=/home/foo/sw/lib/
./configure --prefix=/home/foo/sw -I/home/foo/sw/include -L/home/foo/sw/lib/

But I can't seem to get the syntax right. If anyone can help me out, that would be greatly appreciated. THANKS!

Source: (StackOverflow)