Compiling 32 bit programs on 64 bit OPENSUSE

December 2, 2009

Today, i was programming and i coded the statement below:
value = reinterpret_cast (element);
but i forgot that i was coding on an 64 bit machine and OS. when i compiled i got an error
like this:
Record.h:37: error: cast from ‘Buffer*’ to ‘U32’ loses precision
which was actually telling me that a pointer on a 64 bit OS is 8 byte not 4 byte. So i can’t have enough precision. Basically this reminded me that i am compiling this stuff on 64 bit computer and trying to reduce the 8 byte pointer into 4 bytes which is quite awkward.
So i tried to compile it using -m32 switch in 32 bits. But suddenly i got several errors like below:

“cannot find -lgcc_s”
“skipping incompatible …/”
“skipping incompatible …/libgcc.a when searching for -libgcc ”

Here i am gonna tell you the easiest way to correct these errors:
The only thing you have to do is go to YAST –> Software MANAGEMENT
after that you have to choose the Patterns options.

Choose the 32-Bit Runtime Environment Choose all of them and install.
If any confliction occurs, and you are not sure to install it , then don’t install it.
That’s all folks.
If you have such errors like above try to find the 32bit-devel libraries..

That’s all folks…

If you have different erros, please post below i will try to help.


Cast Operations in C/C++

November 28, 2009

Lately, i have been looking at my old c/c++ codes. Suddenly i realised that it is quite diffucult to read the code where i have casted different data types to each other by using old style C casting. (Type) Another Type. I Even sometimes cast an integer to an integer pointer. But it is quite hard to read what i am casting into what. So i had a research whether there is something new to casting. And it turns out there was.

Today i am gonna tell you about 4 different casting styles:
1) static_cast
2) const_cast
3) dynamic_cast
4) reinterpret_cast

dynamic_cast (expression)
reinterpret_cast (expression)
static_cast (expression)
const_cast (expression)


static_cast is the most useful cast. It can be used to perform any implicit cast. When an implicit conversion loses some information, some compilers will produce warnings, and static_cast will eliminate these warnings. Making implicit conversion through static_cast is also useful to resolve ambiguity or to clarify the conversion presence. It also can be used to call an unary constructor, declared as explicit. It also can be used to cast up and down a class hierarchy, like dynamic_cast, except that no runtime checking is performed.

Here is an example:
casting an int to a double for the purpose of avoiding truncation due to integer division:

double result = static_cast(4)/5;


* Static casts are only available in C++.
* Static casts can be used to convert one type into another, but should not be used for to cast away const-ness or to cast between non-pointer and pointer types.


const_cast is used to apply or remove const or volatile qualifier from a variable.

Here is an example:
casts a const pointer to a non-const pointer to pass into a function:

void func(char *);

const char *x = "abcd";

*Const casts are only available in C++.
*Const casts are used to strip the const-ness or volatile-ness from a variable.


dynamic_cast is used on polymorphic pointers or references to move up or down a class hierarchy. Note that dynamic_cast performs runtime-checks: if the object’s type is not the one expected, it will return NULL during a pointer-cast and throw a std::bad_cast exception during a reference-cast.

Here is an example:
class CBase { };
class CDerived: public CBase { };

CBase b; CBase* pb;
CDerived d; CDerived* pd;

pb = dynamic_cast(&d); // ok: derived-to-base
pd = dynamic_cast(&b); // wrong: base-to-derived

The second conversion in this piece of code would produce a compilation error since base-to-derived conversions are not allowed with dynamic_cast unless the base class is polymorphic.

Compatibility note: dynamic_cast requires the Run-Time Type Information (RTTI) to keep track of dynamic types. Some compilers support this feature as an option which is disabled by default. This must be enabled for runtime type checking using dynamic_cast to work properly.


reinterpret_cast converts any pointer type to any other pointer type, even of unrelated classes. The operation result is a simple binary copy of the value from one pointer to the other. All pointer conversions are allowed: neither the content pointed nor the pointer type itself is checked.

It can also cast pointers to or from integer types. The format in which this integer value represents a pointer is platform-specific. The only guarantee is that a pointer cast to an integer type large enough to fully contain it, is granted to be able to be cast back to a valid pointer.

The conversions that can be performed by reinterpret_cast but not by static_cast have no specific uses in C++ are low-level operations, whose interpretation results in code which is generally system-specific, and thus non-portable. For example:

class A {};
class B {};
A * a = new A;
B * b = reinterpret_cast(a);

This is valid C++ code, although it does not make much sense, since now we have a pointer that points to an object of an incompatible class, and thus dereferencing it is unsafe.

One Last Thing as An Type Identifier :

typeid (expression)

This operator returns a reference to a constant object of type type_info that is defined in the standard header file . This returned value can be compared with another one using operators == and != or can serve to obtain a null-terminated character sequence representing the data type or class name by using its name() member.

// typeid
using namespace std;

int main () {
int * a,b;
a=0; b=0;
if (typeid(a) != typeid(b))
cout << "a and b are of different types:\n";
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
return 0;


a and b are of different types:
a is: int *
b is: int

When typeid is applied to classes typeid uses the RTTI to keep track of the type of dynamic objects. When typeid is applied to an expression whose type is a polymorphic class, the result is the type of the most derived complete object:

// typeid, polymorphic class
using namespace std;

class CBase { virtual void f(){} };
class CDerived : public CBase {};

int main () {
try {
CBase* a = new CBase;
CBase* b = new CDerived;
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
cout << "*a is: " << typeid(*a).name() << '\n';
cout << "*b is: " << typeid(*b).name() << '\n';
} catch (exception& e) { cout << "Exception: " << e.what() << endl; }
return 0;


a is: class CBase *
b is: class CBase *
*a is: class CBase
*b is: class CDerived

Notice how the type that typeid considers for pointers is the pointer type itself (both a and b are of type class CBase *). However, when typeid is applied to objects (like *a and *b) typeid yields their dynamic type (i.e. the type of their most derived complete object).

If the type typeid evaluates is a pointer preceded by the dereference operator (*), and this pointer has a null value, typeid throws a bad_typeid exception.


Creating an Ad-Hoc Network Between Two Open-Suse Installed Computers

November 25, 2009

Hi fellows,

Lately my wireless router broke down and i sent it to be repaired. But the problems started to arise because without a wireless router i wasn’t able to share my Internet connection. So i had it on my mind that i can solve this problem by connecting only one computer directly to the modem and making an ad-hoc connection between the remaining computers and sharing the Internet. So the problem’s first phase was to setup an ad-hoc network, Since all my OS’s are OPENSUSE (I like to pronounce it like “Susie”,because this reminds me my dream girl) , this tutorial will show you how to setup an ad-hoc network between openSUSE installed machines. Then in another tutorial I will teach you how to share Internet connection.

There are 3 ways to do this :

1) Ad-Hoc connection setup with Network Manager. (Probably the easiest)

Do the things on the computer which directly connects to modem :

  • Left click on the Network Manager icon and select Create New Wireless Network
  • Specify an ad-hoc network name. For example: “VEB61”
  • Select security method
  • Click the Create button
  • Right click on the Network Manager icon, select Edit Connections.
  • Select the Wireless tab, select the ad hoc network name and click the edit button.
  • On the Wireless tab set the mode to Ad-hoc
  • Select the Ipv4 Settings tab select the Manual method in the drop down
  • Click the Add button and enter a local IP address, Net mask and Gateway, i.e.,, and respectively.
  • Leave DNS Servers and Search Domains blank
  • Click Apply
  • Left click on the Network Manager icon and select Connect to Hidden Wireless Network
  • Select ad hoc network name on the connection drop down and click Connect.


On the other computers :

  • Left click on the Network Manager icon and select Connect to Hidden Wireless Network
  • TYPE “VEB61” and click connect. (Ad hoc network name created above.)
  • Right click on the Network Manager icon, select Edit Connections.
  • Select the Wireless tab, select the ad hoc network name and click the edit button.
  • On the Wireless tab set the mode to Ad-hoc
  • Select the Ipv4 Settings tab select the Manual method in the drop down
  • Click the Add button and enter a local IP address, Net mask and Gateway, i.e.,, and respectively.
    • Note: The IP address for every machine must be different
  • Leave DNS Servers and Search Domains blank
  • Click Apply

2) Ad-Hoc connection setup without Network Manager.


  • in YaST disable Network Manager (NM)
  • as a root bring down the wireless interface
# ip link set wlan0 down
  • set the domain id and set the ad-hoc mode
# iwconfig wlan0 essid VEB61 mode Ad-Hoc
  • bring up the interface
# ip link set wlan0 up
  • set the IP address manually
# ip link addr add dev wlan0
  • Repeat the procedure on all interfaces that should communicate together. Select unique IP address for each interface.


2) Ad-Hoc connection setup with Yast.

  • YaST -> Network devices -> Network Card
  • select ifup, click Next
  • select card, Edit
  • select “Static address setup” and fill up the IP address, Next
  • select “Operating Mode” Ad-Hoc and set ESSID to your domain id
  • select authentication, Next, Finish
  • Repeat on all interfaces.



PTLSIM Setup On OpenSuse With G++4.1

September 29, 2009

Lately , i have found my self using ptlsim.

Obviously , the first step to use ptlsim is to install it. Here , i will tell you how to install ptlsim on opensuse with g++4.1and some troubleshooting about the installation and later phases of the usage. I will also keep this document up to date as much as possible.

Installation Steps:

1) Go to, download the latest package, what i have downloaded was ptlsim-20090314-r229.

2) After that extract this package.

3) Open a console and change your directory to this ptlsim directory.

4) In the ptlsim directory, open Makefile and edit the line:

– CC = g++-4.3  change this line to CC = g++-4.1

5) then turn back to konsole, and type make

6) you may have several errors like

stubs-32.h not found


– Download and install glibc , // zypper install glibc

7) if this error has occured , type “make clean” and when cleaning process is finished , type “make ” again.

8) possibly the ptlsim will be successfully compiled and ready use.

Trouble Shooting:

In the working phase, you may get an error like this:

-/sysdeps/x86_64/cacheinfo.c:197: handle_intel: Assertion `maxidx >= 2′ failed.


This is an assertion from glibc running on an Intel CPU. It assumes that the cpuid instruction has minimum level of support, but ptlsim doesn’t provide it.You can either remove the assertion from glibc, or more easily, hack the cpuid instruction in ptlsim such that it claims it has a higher level of support than it provides.

– This can be done by editing the  ptlsim/decode-complex.cpp file

– Search for the  void assist_cpuid(Context& ctx) function

– and edit the case:

   case 0: {
     // Max avail function spec and vendor ID:
    const W32* vendor = (const W32*)&cpuid_vendor;
    // rax = 1; // only one extended function  // Comment this

    // add this
    rax = 2; // only one extended function (but fake more otherwise glibc
             // fails an assertion)
     rbx = vendor[0];
     rdx = vendor[1];
     rcx = vendor[2];

– Finally recompile and use ptlsim. That’s all folks.

OpenSuse 11.1 & Ati Radeon HD 3470

September 16, 2009

Lately, i have been having problem with my Sony vaio sr 39vn about 3d hardware accerelation. Finally i have discovered that the driver installed is not exploitting my graphic card to its full extent.

First of all, when i first try t install the ati graphic driver, i had lots of problems. But i have figured those errors and corrected them.

So, long story in short,

Step 1. go to ati’s driver page. Choose the appropriate os and graphic card.

Step 2. In my case, it was

ATI Catalyst™ 9.8 Proprietary Linux x86 Display Driver 93.6 MB 9.9 9/9/2009

i downloaded a file named

Step 3. Before installation of this file. You should be sure that the packages are installed in your system, If not installed, you can install those by using YaSt

XOrg 6.8, 6.9, 7.0, 7.1, 7.2, 7.3 or 7.4
Linux kernel 2.6 or above (  source package is more appropriate, but it is ok to have header package alone)
glibc version 2.2 or 2.3

For ati’s catalyst to work properly , you have to install some more:

XFree86-Mesa-libGL // obsolete library, but instead of this Suse   comes LibGL you can check by typing

vehbi@linux-s9q5:~> rpm -qa –last | grep Mesa
Mesa-32bit-7.2-10.3.6                         Fri 04 Sep 2009 02:04:00 PM EEST
Mesa-7.2-10.3.6                               Fri 04 Sep 2009 01:14:43 PM EEST

If this is the output, then you do not worry, everything is OK.

XFree86-libs // obsolete , opensuse users do not need to install this either.

Step 4. Enabling POSIX Shared Memory (/dev/shm) support which is required for 3D applications.

To enable POSIX Shared Memory on your system, perform the following as root:

  1. Add the following line to /etc/fstab (if it isn’t there already): tmpfs /dev/shm tmpfs defaults 0 0
  2. Mount shared memory as follows: mount /dev/shm
  3. Issue the following command to check that it mounted properly: mount | grep “shm”

If the mount was successful, then the following output (or similar) should appear:

tmpfs on /dev/shm type tmpfs (rw)

Step 4. Reboot.


ATI Catalyst™ 9.8 Proprietary Linux x86 Display Driver

OpenSuse 11.1 & VirtualBox

September 15, 2009

Lately, i have been struggling with Sun’s virtualbox on Suse 11.1 to get it working. First of all my advice for you all not to install OSE( Open Source Edition) until it becomes fully functional. For now it would be better to download the binary from the sun’s website.

So here is how you can do it.



  1. First, you’ll have to download the package from Sun’s website.

  2. Then you should download the appropriate package according to your OS (32 & 64). For open suse , there is a special link. If you don’t know whether your linux is 32 or 64. you can check it by typing “uname -a” on the command line.

    vehbi@linux-s9q5:~> uname -a
    Linux linux-s9q5 #1 SMP 2009-08-15 17:53:59 +0200 x86_64 x86_64 x86_64 GNU/Linux

  3. After you download the rpm(It is an rpm in our case , since we are opensuse users, it may differ on different linuxs.)

    Type on the command line

    sudo rpm -i VirtualBox-3.0.6_52128_openSUSE111-1.x86_64 
  4. That’s it for installing Virtualbox.  But you will encounter, mostly so many errors. Let’s have a look at the possible errors you may encounter.

Problems And Fixes:

  1. VirtualBox’s library requirements. Install the following:
  2. ryan@rawswift:~/Desktop> VirtualBox
    WARNING: The vboxdrv kernel module is not loaded. Either there is no module
             available for the current kernel ( or it failed to
             load. Please recompile the kernel module and install it by
               sudo /etc/init.d/vboxdrv setup
             You will not be able to start VMs until this problem is fixed.
    /usr/bin/VirtualBox: line 72: /usr/lib/virtualbox/VirtualBox: Permission denied
    /usr/bin/VirtualBox: line 72: exec: /usr/lib/virtualbox/VirtualBox: cannot execute: Success

    If the above error appears, you should run ‘vboxdrv’ script to create the VirtualBox kernel module:

    ryan@rawswift:~/Desktop> sudo /etc/init.d/vboxdrv setup
    Stopping VirtualBox kernel module                                    done
    Removing old VirtualBox netflt kernel module                         done
    Removing old VirtualBox kernel module                                done
    Recompiling VirtualBox kernel module                                 failed
      (Look at /var/log/vbox-install.log to find out what went wrong)

    If it fails to compile, install ‘kernel-source‘ through YaST. Then run ‘/etc/init.d/vboxdrv setup’ again.

    ryan@rawswift:~/Desktop> sudo /etc/init.d/vboxdrv setup
    Stopping VirtualBox kernel module                                    done
    Removing old VirtualBox netflt kernel module                         done
    Removing old VirtualBox kernel module                                done
    Recompiling VirtualBox kernel module                                 done
    Starting VirtualBox kernel module                                    done
  3. Permission denied:
    ryan@rawswift:~/Desktop> VirtualBox
    /usr/bin/VirtualBox: line 72: /usr/lib/virtualbox/VirtualBox: Permission denied
    /usr/bin/VirtualBox: line 72: exec: /usr/lib/virtualbox/VirtualBox: cannot execute: Success

    Run ‘chmod’ on ‘VirtualBox’. This will set the execute bit:

    sudo chmod +x /usr/lib/virtualbox/VirtualBox
  4. Driver mismatch. If an error box appear when you ‘Start’ a virtual machine:
    The VirtualBox support driver which is running is from a different version of VirtualBox.
    You can correct this by stopping all running instances of VirtualBox and reinstalling the software.
    Result Code:    NS_ERROR_FAILURE (0x80004005)
    Component:      Console
    Interface:      IConsole {e3c6d4a1-a935-47ca-b16d-f9e9c496e53e}

    Check your VirtualBox package platform (64-bit or 32-bit, see the tutorial above).

  5. USB ERRORS: Sometimes virtual box may not recognize the usb devices. Or sometimes all the devices may seem gray(inoperable). If this is the case, do the following in opensuse:

    Step 1. Check that the user group ID vboxusers exists. If not, create the user group vboxusers using YaST -> Security and Users -> Group Management.

    Step 2. Discover the group ID (GID) number for group ID vboxusers. You can do this using YaST -> Security and Users -> Group Management. A new window will appear with a drop-down menu named Set Filter in the lower-right-hand corner. Change Set Filter to System Groups and scroll down to near the bottom of the list, where you should see the group name vboxusers with its group ID number to the right of vboxusers. Alternative way: grep vbox /etc/group as user root.

    Step 3. Add the desired user ID (e.g. john) to the user group vboxusers. Click the button in the lower-right-hand corner labeled Finish.

    Step 4. Add the following to the end of the file /etc/fstab:

    sys/bus/usb/drivers /proc/bus/usb usbfs devgid=XXX,devmode=664 0 0

    and add following line to /etc/init.d/boot.local

    mount -a
    Step 5. Reboot.

Note: Some of the parts above are from different places. If you have any further question, mail
me at