Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro++? Link problems with C program

This thread is locked; no one can reply to it. rss feed Print
Allegro++? Link problems with C program
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Hey,

I am trying to compile a simple c program, but I can't use gcc without gettings errors about undefined references to C++ functions. I have to use g++. I'm linking to the allegro monolith.


e:\LIBS\LIBS71Distro\Allegro523MinGW71\Video>gcc -Wall -Wextra -Wshadow -o StaticTest.exe -I %A5INCDIR% static.c -DALLEGRO_STATICLINK -L %A5LNKDIR% -lallegro_monolith-static %A5STATICLIBS% -static-libgcc
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xba): undefined reference to `__cxa_guard_acquire'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xb06): undefined reference to `__cxa_guard_acquire'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xb26): undefined reference to `__cxa_guard_release'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xb49): undefined reference to `__cxa_guard_release'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xb72): undefined reference to `__cxa_guard_abort'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.text+0xb88): undefined reference to `__cxa_guard_abort'
E:\LIBS\LIBS71Distro\Allegro523MinGW71\lib\liballegro_monolith-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.eh_frame+0x63): undefined reference to `__gxx_personality_v0'
collect2.exe: error: ld returned 1 exit status

e:\LIBS\LIBS71Distro\Allegro523MinGW71\Video>g++ -Wall -Wextra -Wshadow -o StaticTest.exe -I %A5INCDIR% static.c -DALLEGRO_STATICLINK -L %A5LNKDIR% -lallegro_monolith-static %A5STATICLIBS% -static-libstdc++ -static-libgcc

e:\LIBS\LIBS71Distro\Allegro523MinGW71\Video>

Is there any way around this? Or is Allegro on Windows a C++ library now? Can I get rid of the D3D and C++ dependency somehow?

Neil Roy
Member #2,229
April 2002
avatar

Can you not compile it with gcc?

I don't know about the latest Allegro, the last version I have is 522 compiled by you and my Deluxe Pacman 2 game, written in C and compiled with gcc is fine. But then I also set the -std=gnu11 flag for mine, which is the C 2011 standard with gnu extensions, but never had a problem. Unless of course, something drastic changed in 523?

Maybe try either gcc, or set the -std flag to make certain it is set to C only?

---
“I love you too.” - last words of Wanda Roy

Elias
Member #358
May 2000

Can I get rid of the D3D and C++ dependency somehow?

Only way is to modify the source code. It's also not just D3D any longer but someone used C++ for joystick/haptic code as well: https://github.com/liballeg/allegro5/tree/master/src/win

The D3D code was C++ also for A4 btw. so it has been like that for a long time. You can still use gcc btw., just add -lstdc++ at the end manually. And you can also use the option to include static C++ librares (I forget what it is).

--
"Either help out or stop whining" - Evert

Neil Roy
Member #2,229
April 2002
avatar

This mixing C and C++ is not good for the library at all. It should use either one or the other. There's good reason why most libraries stick to C, as you can easily use it for C and C++ or other languages as C ports more easily over, but C++ does not. This can only lead to more problems.

---
“I love you too.” - last words of Wanda Roy

SiegeLord
Member #7,827
October 2006
avatar

Many Windows APIs are C++ only, so there's only so much that can be done. It might be the case that we can try to disable exceptions which should remove these personality etc things, but I don't know for sure.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Neil Roy
Member #2,229
April 2002
avatar

SiegeLord said:

Many Windows APIs are C++ only

SFML is, that's all I know of. I don't know how you get "many"? SDL certainly isn't C++. Most of the popular ones, except SFML are C, mainly due to portability and speed. But I think it is something that needs to be standardized in Allegro one way or another or you will start getting many more questions from people who are having problems like this and only end up driving people away.

I'll personally always stick to C APIs, mainly because of the portability issues, and also because I have a choice whether to use C or C++. And I compile C with GCC for reasons I won't get into here.

---
“I love you too.” - last words of Wanda Roy

Elias
Member #358
May 2000

Also D3D has a C API, it's just more awkward to use than their C++ one.

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Elias said:

You can still use gcc btw., just add -lstdc++ at the end manually. And you can also use the option to include static C++ librares (I forget what it is).

gcc works if I use "-static -lstdc++", but not "-static-libstdc++".

I thought the other language ports of Allegro depended on it being a C library?

Chris Katko
Member #1,881
January 2002
avatar

Neil Roy said:

This mixing C and C++ is not good for the library at all. It should use either one or the other.

I thought you weren't using Allegro anymore. ::) And it's worked so well that you didn't notice it in Allegro 5... or Allegro 4.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy said:

This mixing C and C++ is not good for the library at all. It should use either one or the other.

I thought you weren't using Allegro anymore. ::) And it's worked so well that you didn't notice it in Allegro 5... or Allegro 4.

I'm guessing he only said that he's never going to use allegro again because I've been so hard on him lately. And my reply to what he said was pretty harsh. I shouldn't have been so critical. It just bothers me when people badmouth allegro, especially when they do it here on allegro.cc. It's like going onto SDL's forums or mailing list or whatever they use and saying SDL sucks. I'm sorry for being so harsh though. It's not my intention to drive anyone away from allegro or allegro.cc. There are so few of us left now anyway.

Back to linking, this whole situation makes me wonder if the D3D driver and the haptic driver should have been made into addons, instead of integrating them into Allegro proper. Too late now, and I guess it doesn't really matter.

I didn't think you could link the C++ standard lib with gcc. But I guess if the symbols are properly mangled and are unique, then it should work.

Neil Roy
Member #2,229
April 2002
avatar

I thought you weren't using Allegro anymore. ::) And it's worked so well that you didn't notice it in Allegro 5... or Allegro 4.

Was there CPP code in 4? Where? I still have the source for 4.2. But if it can work with a C compiler, fine. There are still issues with C++ not being as portable as C, due to different non-standard implementations of C++, but if it can be made to work, great.

Anyhow, yeah, okay, I'll stop contributing. No problem.

---
“I love you too.” - last words of Wanda Roy

SiegeLord
Member #7,827
October 2006
avatar

Thing is, this has been true since essentially beginning of Allegro 5, around 10 years ago. Yes, occasionally there are threads that mention this issue (a couple a year), and it does complicate the distribution (as we need to at least specify which exception handling mechanism we use). I think we might be able to get away with not linking the C++ standard library and exceptions, but it appears to be complicated to accomplish. Either way, this doesn't seem to be a problem in practice.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

beoran
Member #12,636
March 2011

Personally, I am in favour of porting the parts of Allegro that are C++ to C, but I have to admit it is a lot harder to use the direct3d and xinput API from C. On OSX, we also use objective C because it is easier than using a pure C API. And on android we use some java as well. Ideally most of it should be C, but practically, on many platform, we have to use the platform's preferred language for convenience, abs sometimes from neccecity. AFAIK, SDL does the same.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I have nothing against Allegro using C++, but it seems like it should be in separate addons to preserve the integrity of the core C code. But I think the D3D code is heavily integrated into allegro proper on Windows (don't really know if it is though, would have to look into it) and it would be like pulling teeth trying to separate the two.

Go to: