Fedora 18 hostname resolution problems

After you have installed Fedora 18, you probably noticed that it starts up with the default localhost.localdomain hostname. In the former versions of Fedora the HOSTNAME variable that determined the hostname of your machine was stored in /etc/sysconfig/network file, but starting from from Fedora 18 it is not there anymore. Furtunately there is a command that can be used to update your hostname:

$ sudo hostnamectl set-hostname DESIRED_HOST_NAME

The hostname command can be used to check whether the hostname was successfully updated or not on your machine. However you might notice that pinging or nslookup your own hostname will not work and you gey and error for the hostname -f.

#The hostname will return your current hostname
$ hostname

#However it is not able to reslove it (nor does the ping or nsloookup)
$hostname -f
hostname: Name or service not known

The reason behind of this is that you probably don’t have a DNS server (or it is misconfigured). The easy solution to fix this without having a DNS server is to edit the nsswitch.conf file and add myhostname for host resolution.

Please be sure that the nss-myhostname is installed on your machine.

$ sudo yum install nss-myhostname

Edit the /etc/nsswitch.conf file and add myhostname value to hosts section.

$ sudo vi /etc/nsswitch.conf

#Note: just add the myhostname value as you see below and not your real host name!!!
hosts:      files dns myhostname

After these changes you shall be able to resolve your own hostname with hostname -f or even with nslookup.

You might think that editing of /etc/hosts file is also a good workaround, but please consider that if your machine is getting its IP address dynamically then you always need to update the /etc/hosts file, but with the above solution your hostname will be resolved always correctly even in case of variable IP addresses.

Debug cross-compiled executable on Raspberry Pi from Eclipse

If you were able to launch a cross compiled executable on the target machine (Raspberry Pi) as described in my former post, then you probably would like to debug it remotely as well.

Update crosstool-ng
I have already described how to setup crosstool-ng for cross-compiling purposes, but in order to enable cross-debug support a few other steps needs to be done. First of all you need to install some additional packages from Fedora repository.

su - #change to root
#Install dependencies for crostool-ng debug support
yum install expat expat-devel python python-devel

If these packages are not installed then probably you will get the following error message during the build of crosstool-ng tools.

[INFO ]  Installing cross-gdb
[ERROR]    configure: error: expat is missing or unusable
[ERROR]    make[2]: *** [configure-gdb] Error 1

After the dependencies are successfully installed just need to follow the same steps what are described in the Configure the toolchain chapter and additional to those steps select the required debug options in the menuconfig of ct-ng.

  • Debug facilities
    • Enable “ltrace”
    • Enable “gdb”
    • Enable “duma”
    • Enable “dmalloc”
    • Keep “strace” on disable since it does not seem to build with crosstool-ng 1.16.0

Save the changes, exit from the menuconfig and build the crosstool-ng tools as usual…

Debug Configuration in Eclipse
I suppose you have already setup Run Configuration in Eclipse and successfully executed your cross-compiled binary on the target machine as described here. If not then it is the right time to do it. After it is done, just open Debug Configuration for your project and select the Debugger tab.

GDB debugger

Fill the GDB debugger field with the browse button. The cross-debugger shall be available under your crostool-ng tools:


Click on the Debug button and Eclipse is going to copy your cross-compiled binaries to remote machine and start to debug it remotely.

Eclipse Remote Debug

Launch cross-compiled executable on Raspberry Pi from Eclipse

If you have cross compiled your source files as described in the former post, then you probably want to execute your cross compiled binaries on the target machine. The simplest and most time consuming way is just to manually copy over the binaries to Raspberry Pi. Luckily you can save some time, since the Eclipse has a built-in support to copy and execute the binaries remotely. In order to do this just follow the description below.

Run Configuration
Open the “Run Configuration” menu and create a new “C/C++ Remote Application”. As you can see the “Connection” dropdown will be empty by default, and we need to setup a connection to Raspberry Pi.

Default Run Configuration with empty Connection

New Linux Connection
To create a connection click on the “New” button next to the connection dropdown box and select the Linux Connection and configure the connection as shown on the following screenshots.

Configure Raspberry Pi host name (rpi already present in /etc/hosts)

Files Menu

Processes Menu

Shells Menu

SSH Terminals Menu

Remote File setup
You need to setup the location of remote file by clicking on the “Browse” button. Please note that the full qualified path can be browsed, but you need to type the binary executable name as well. In other words the “Remote Absolute File Path for C/C++ Application” field shall contain a path like /home/pi/Workspace/helloworld where the helloworld is the name of the binary executable. It is also important that the directories must be present on the target system and the user what you are using to connect must have sufficient rights to copy the file to that directory.

Properly configured Run Configuration dialog

Run the executable remotely
When you click on the “Run” button, then Eclipse will transfer the executable to the target machine, launch it and display the standard error and output on the Eclipse console:

Console out in Eclipse

Note: As an alternative you can share the data with sshfs or nfs between your workstation and target board.

Setup Eclipse for cross-compiling

After you have successfully created your cross-compiling toolchain with crosstool-ng as described in Cross compiling kernel for Raspberry Pi on Fedora 17 you probably want to use the tools not only form command line but also from a rich IDE like Eclipse.

Install Eclipse IDE for C/C++ Developers
Navigate to Eclipse download page and download the Eclipse IDE for C/C++ Developers and extract it. This post is based on the Juno version of Eclipse for 64bit Linux platforms, but probably with slight modification you can apply it for later versions as well.

Optional step: After the Eclipse has been downloaded and extracted you can create a desktop icon for it if you wish:

gnome-desktop-item-edit ~/Desktop/eclipse_cpp.desktop --create-new

Create a C or C++ Project
Start Eclipse and create a new C Project from New menu (description shall work also for C++). On the first dialogue screen, please select the “Hello World ANSI C Project” with “Cross GCC” Toolchains and press the Next button, the settings on the following dialogues can remain as default. On the last dialogue called “Cross GCC Command”, please select the Cross compiler prefix and also the Toolchain Path as shown in the screenshot below.

Verifying the projects
After you have successfully executed the above steps your projects can be compiled on your desktop and executed on the target machine. Eclipse will load all required libraries and tools from the above defined Toolchain path. You can double-check your Eclipse project as shown in the screenshot:

Eclipse with with multiple cross compile projects