Amber Jain's weblog (OLD)

Visit my new weblog at

Posts Tagged ‘build

Error on debian lenny when updating Virtualbox 1.x to 3.x

with one comment

I’m running debian lenny that was setup from minimal netinst. I had installed virtualbox from lenny repos ( But then I thought of upgrading to newer version of virtualbox because virtualbox 1.x refused to capture my mouse pointer inside guest OS. So, I added lenny-backports repos ( to my /etc/apt/sources.list and did ‘sudo apt-get install -t lenny-backports virtualbox). Then when I started virtualbox 3.x, and tried starting (/booting) any guest OS, I got this error:
Virtualbox error

When I was installing Virtuabox from lenny-backports, the ‘apt-get install’ output was:
Lines number 90,91,92 and 108, 109, 110, 111, 112 are worth noting in that paste.
(Note: If you want to check out log of output from ‘apt-get install’ on debian, goto /var/log/apt/ and open term.log in your text editor as root)

I then tried finding some help on #debian at
User ‘qq-‘ there suggested that I try rebooting. When I rebooted, I got this message in debian boot messages scrollback:

Starting Virtualbox kernel modules. No suitable vboxnetflt module for running kernel found. Failed

After some discussion, users ‘qq-‘ and ‘jpinx-eeepc’ suggested that I try installing linux-image-2.6.32-bpo.5-686 (you can see mentions of this linux kernel version in the paste linked above). So, I did ‘sudo apt-get install -t lenny-backports linux-image-2.6.32-bpo.5-686’.
When I started Virtualbox this time……wooohooo NO ERRORS THIS TIME πŸ˜€

So, in short, install the latest/stable/recommended linux kernel version if you get a similar error.

Written by Amber Jain

June 21, 2010 at 3:47 PM

Compile C code (that uses libraries) using gcc on Windows

with one comment

Ok. I know that you probably know how to compile code using gcc. You use something like following command:

gcc -Wall -g input_filename.c -o output_filename


gcc -Wall -c -g input_filename.c
gcc -Wall -o output_filename input_filename.c

Right? Ok. RTFM for more details.

The above compile command is really easy and works on Linux, BSD, Unix, Windows etc. On Linux/BSD/Unix, compiling code that uses some library is not so difficult and (almost?) same across different distributions (Makefiles exist to ease the compile/build process). But on Windows, it’s a bit different. Personally, it took me more than half an hour and help of fine folks at #mingw (at to understand how to compile a C program that uses some library.

In this post, I’ll take libcurl as an example to illustrate compiling a C program that uses some library. libcurl is the multiprotocol file transfer library.
For this post, we will try compiling and building (an executable) using following example code:


#include <stdio.h>
#include <curl/curl.h>

int main(void)
// Source:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "");
res = curl_easy_perform(curl);
/* always cleanup */
return 0;

NOTE: Download and extract this to C:\ so that your directory structure should look like:
More libcurl downloads are here.

Let me start with the command that is the ultimate purpose of this post (i.e. to compile C code on Windows that uses some library). Here:

gcc main.o -o test_binary -LC:\libcurl-7.19.3-win32-ssl-msvc\lib\Release -lcurllib

Here are details of various command line arguments (in order) in above command:

#1. gcc: The first command line argument, ‘gcc’, is the name of compiler.

#2. main.o: The second argument, ‘main.o’, is the name of object file input to compiler that was previously compiled from source code using:
gcc -Wall -c -g main.c

#3. -o: The third argument, ‘-o’, specifies that the argument immediately following this argument is the name of output binary executable, as per the needs of the programmer (or the person who is compiling the code). Also, see #4 that follows.

#4. test_binary: The fourth argument, ‘test_binary’, is the name of output binary executable, as per the needs of the programmer (or the person who is compiling the code). This is bind to ‘-o’ command line argument and should immediately follow it. Also, see #3 that precedes.

#5. -LC:\libcurl-7.19.3-win32-ssl-msvc\lib\Release: Now comes the real part (Pause here and remind yourself the actual purpose of this post). The fifth argument, ‘-L’, specifies that the string appended to -L flag/option is the directory that should be searched for library files specified by ‘-l’ flag (Also, see #6 that follows). Mind you, there is *no* space between the option flag (-L) and the library directory name.

#6. -lcurllib: The sixth argument, ‘-l’, tells linker that the string appended to -l option flag is the library that is to be searched for unresolved symbols when linking. The actual file will be something like either libmylib.a or mylib.lib or something similar (@experts: right?).

I must confess here that I’m still unable to use makefiles *on windows* to automate the process of compiling and building (though I tried only for less than 1 hour). Manual compiling is surely cumbersome, but who cares πŸ˜€ I very rarely compile my code on Windows and so, I’ll get past this hurdle too sometime in future when I get some free time. And, maybe I’ll do a blogpost on it too.

That’s it. I guess that you get it. If you still have questions/problems, you can try following:
1. Get help from #mingw (
2. RTFM.
3. Stanford’s Unix Programming Tools contains some useful information (It’s really useful, even if it is for Unix. Read it.).

PS: In case you get ‘XYZ.dll not found’ error when running the executable, just find the right DLL(s) [on the internet] that are missing and put them in same directory that contains the binary executable. Easy, isn’t it?


Written by Amber Jain

May 18, 2010 at 7:10 PM