How to call function al_draw_multiline_text?
thatrabbit

Hello. I am running latest version of Allegro.

I see this function in docs:

https://liballeg.org/a5docs/trunk/font.html#al_draw_multiline_text

In my code I have at least:

#SelectExpand
1#include <allegro5/allegro_font.h> 2#include <allegro5/allegro_ttf.h> 3... 4al_init_font_addon(); 5al_init_ttf_addon(); 6...

When I compile, I am told "undefined reference to <al_draw_multiline_text>".

How do I use that function?

I can use al_draw_text okay. If I can get built-in newlines that helps a lot.

kenmasters1976

Does ex_font_multiline from the Allegro examples work?.

RmBeer2

You also need to link their library. (-lallegro_font -lallegro_ttf)

LennyLen
RmBeer2 said:

You also need to link their library. (-lallegro_font -lallegro_ttf)

I think it's safe to assume he's linking correctly if al_draw_text() is working.

My low-tech suggestion - are you sure you spelled the function correctly?

bamccaig

Which version of Allegro do you have installed? Seems that function was added in 5.1.9. ??? If you spelled it correctly and al_draw_text works then too old of a distribution seems like the only explanation left. :P

Mark Oates

Also possible you may be using the wrong function signature, which can result in an undefined reference.

bamccaig

That's true, but only if he forward declared the signature himself. Otherwise, the compiler would choke before the linker was invoked. :-*

RmBeer2

What signature?? i get lost...

Edgar Reynaldo

al_draw_multiline_text was added in Allegro 5.1.9. You must be linking to an old version of allegro, or not linking to the allegro font addon.

bamccaig
RmBeer2 said:

What signature?? i get lost...

f1.cpp#SelectExpand
1void f1(int * x) 2{ 3 *x *= 2; 4}

main.cpp#SelectExpand
1void f1(const char *); 2 3int main(int argc, char * argv[]) 4{ 5 f1("Hello, World!\n"); 6 7 return 0; 8}

g++ -Wall f1.cpp -c
g++ -Wall main.cpp -c
g++ -Wall f1.o main.o
main.o: In function `main':
main.cpp:(.text+0x17): undefined reference to `f1(char const*)'
collect2: error: ld returned 1 exit status

f1 is a real function, and it has been linked, but the signature doesn't match the one expected by main.o.

Interesting to note that C did not care at all. It compiled and linked without errors. Then it segfaulted at runtime. :-/

RmBeer2

f1.cpp: _Z2f1Pi
main.cpp: _Z2f1PKc

This's a signature? i see...

Saying they have different parameters looks less confusing. Although this is what makes C++ stackable with the same function name.

In that case he should show what is the source code, the compilation line and the compilation output. To be more sure.

Mark Oates

That's a great example, BAM.

thatrabbit

Wow. Thank-you for all the replies! I should have checked back sooner.

I realized multi-line would not help me in this case. Still it is good to know it exists, and I will refer back here when the time comes.

Cheers all!

-- edit

You must be linking to an old version of allegro

Was correct. I am using 5.0.10. Time to upgrade.

Edgar Reynaldo

I have some binaries for Allegro 5.2.5 and MinGW-W64 gcc 8.1.0 on my bitbucket download page. I haven't updated my binary package to 5.2.6 yet, which you can find on the official download page.

Links:

Allegro 5.2.5 and Allegro 4.4.3

https://bitbucket.org/bugsquasher/unofficial-allegro-5-binaries/src/master/

https://bitbucket.org/bugsquasher/unofficial-allegro-5-binaries/downloads/

Official binaries :

https://github.com/liballeg/allegro5/releases

Thread #618234. Printed from Allegro.cc