Undefined reference to `__dso_handle' with PololuQTRSensors

Hello All,

When I try to compile example “PololuQTRRCExample” from PololuQTRSensorsForArduino I’m getting following error:

PololuQTRRCExample.cpp.o: In function `setup':
PololuQTRRCExample.cpp:47: undefined reference to `__dso_handle'
PololuQTRRCExample.cpp:50: undefined reference to `__dso_handle'
PololuQTRRCExample.cpp:50: undefined reference to `__cxa_atexit'

I use arduino 022 and gcc 4.4.3 and avr-gcc 4.4.3.

If I try to workaround this problem modifying the original example by adding initial declaration:

extern "C"
{void *__dso_handle = NULL;}
extern "C"
{void *__cxa_atexit = NULL;}

then I can compile it but it does not work.

I’ve read here: arduino.cc/cgi-bin/yabb2/YaB … 186646/3#3 that gcc 4.4.x can lead to different problems.

Any suggestion will be very much appreciated
Regards
Beny

Hello, beny9.

I tried to reproduce your problem but could not. The example sketch compiled with no errors on my computer.

I downloaded the latest version of PololuQTRSensorsForArduino from here:
pololu.com/docs/0J19/all

I am using Windows Vista and arduino-0022. This version of the IDE uses avr-gcc.exe “version 4.3.2 (WinAVR 20081205)”. What operating system are you using? How did you determine the version number of avr-gcc? I determined my version number by going to my Arduino installation directory and running “hardware\tools\avr\bin\avr-gcc.exe -v” in a Command Prompt.

Also, your version of plain old gcc should not matter. If you are compiling the sketch within the Arduino IDE, it should use avr-gcc, not gcc. The __dso_handle and __cxa_atexit symbols have something to do with shared libraries: a feature that avr-gcc does not support. This makes me think you are using an unusual compiler. You should definitely not try to use plain old gcc to compile programs for an AVR.

–David

Thank you for your prompt answer.

I use Linux Mandriva 2010.2, kernel: 2.6.33.7
gcc version was checked by issuing from konsole: avr-gcc -v
results:

avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-slibdir=/usr/avr/lib --with-bugurl=https://qa.mandriva.com/ --mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release --enable-languages=c,c++ --program-prefix=avr- --build=x86_64-manbo-linux-gnu --host=x86_64-manbo-linux-gnu --disable-threads --target=avr --with-system-zlib --disable-shared --enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libgcj --enable-ssp --disable-libssp --disable-libmudflap --disable-libffi --disable-werror --disable-libgomp --with-ppl --with-cloog --with-python-dir=PYTHON-LIBDIR-NOT-FOUND
Thread model: single
gcc version 4.4.3 (GCC)

Your avr-gcc version is exactly this one, which is recommended to solve this issue. Please refer to the link to arduino forum I enclosed in my first post. The avr-gcc 4.3.1 was mentioned as a buggy one and it is not longer available for Mandriva.

Under my virtual box with xp I can compile and run the example without any problem.
However I do not have mentioned by you avr-gcc. In the hardware\tools\avr\bin folder there is only gcc.

C:\WINDOWS>Z:\arduino-0022\hardware\tools\avr\avr\bin\gcc -v
Using built-in specs.
Target: avr
Configured with: ../gcc-4.3.2/configure --enable-win32-registry=WinAVR-20081205
--with-gmp=/usr/local --with-mpfr=/usr/local --prefix=/c/WinAVR --target=avr --e
nable-languages=c,c++,objc --with-dwarf2 --enable-doc --disable-shared --disable
-libada --disable-libssp --disable-nls --with-pkgversion='WinAVR 20081205' --wit
h-bugurl='URL:http://sourceforge.net/tracker/?atid=520074&group_id=68108&func=br
owse'
Thread model: single
gcc version 4.3.2 (WinAVR 20081205)

Do you have any other idea - how I can get this sensor library working?

Just an update:
In order to get rid of mentioned issues it is necessary to add following flag -fno-use-cxa-atexit to avr-gcc >= V.4.4.x

Unfortunately it is not possible in arduino ide - no way to pass anything to gcc.
The (interim) solution for me was to migrate this project to netbeans. There it works fine.

Regards
Beny

I noticed that your version of avr-gcc in Mandriva Linux was compiled with the --enable-__cxa_atexit option. This is probably causing your problem. Are you able to compile example Arduino sketches for any other libraries?

Here is my avr-gcc -v version info from Ubuntu. It doesn’t have --enable-__cxa_atexit.

Using built-in specs.
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --disable-libssp --build=i486-linux-gnu --host=i486-linux-gnu --target=avr
Thread model: single
gcc version 4.3.3 (GCC)

–David

Hello David,

> Are you able to compile example Arduino sketches for any other libraries?

Some of them. Honestly this (PololuQTRSensors) was the first library which makes me some troubles.
Since I can go ahead with my project and we can influence neither standard gcc in Mandriva nor Arduino IDE let’s keep in mind -fno-use-cxa-atexit as the solution.

Anyway many thanks for your support and good pololu stuff.

Cheers,
Beny

Both gcc and the Arduino IDE are open source, so you should be able to compile your own version of them if you wanted to. I think it will be easier to compile Arduino than avr-gcc.

If your change works then you might be able to influence the person who made the avr-gcc package for Mandriva, or influence the Arduino team.

–David