Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [linker error] undefined reference to 'atexit'

This thread is locked; no one can reply to it. rss feed Print
[linker error] undefined reference to 'atexit'
Denis Sinner
Member #4,278
January 2004

Hi there,
i tried to compile a simple "Hello World" with dev-cpp,
but i get the following errors:
[linker error] undefined reference to 'atexit'
[linker error] undefined reference to 'atexit'
[linker error] undefined reference to 'atexit'
[build error][projekt1.exe]Error1

kdevil
Member #1,075
March 2001
avatar

Any code you care to show us?

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Denis Sinner
Member #4,278
January 2004

#include <allegro.h>

int main(int argc, char **argv){
allegro_init();
allegro_message("Hello World!");
} END_OF_MAIN()

kdevil
Member #1,075
March 2001
avatar

Try this:

#include <allegro.h>

int main()
{
  allegro_init();
  allegro_message("Hello World!");
  allegro_exit();
  return 0;
}
END_OF_MAIN()

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Zaphos
Member #1,468
August 2001

Sounds like a standard (defaultly linked) library is not being linked in. atexit() should certainly exist and be linked in with your project, it's a function in stdlib.h -- did you perhaps toy with the linker settings when you were telling to dev-cpp to link in allegro? If so, try undo-ing those changed.

I would be greatly surprised if kdevil's suggestion works, since atexit() is probably called by allegro regardless of whether an explicit call to allegro_exit is made. There is no reason I know of to explicitly call allegro_exit if you plan to use allegro for the duration of the program runtime; for an allegro game, certainly, the call is probably deadweight.

CGamesPlay
Member #2,559
July 2002
avatar

You must be linking statically, right? Because the dll would have the unresolved symbol else, no?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

gillius
Member #119
April 2000

Guys keep in mind that allegro_init is a macro, as allegro_init is the old-Allegro 3.0 style function. The new function is install_allegro which is compatible with dynamic linking operating systems (such as Windows and Linux) as it contains a driver ID, errno pointer, and atexit pointer to register itself. So atexit is directly used by the allegro_init macro.

Gillius
Gillius's Programming -- https://gillius.org/

kdevil
Member #1,075
March 2001
avatar

Yeah, I'm not really sure why I thought adding allegro_exit() would fix it. It's probably something in the linker settings like Zaphos said.

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Go to: