|
Post by agent725 on Dec 6, 2021 19:04:16 GMT 1
Hello! It has been 10 years ago that I last was making stuff in BaCon. In the meantime I see there's been a lot of great developments. While compiling I ran into a problem: Compiling 'chafa_test.bac'... cc -c chafa_test.bac.c /usr/include/glib-2.0/glib.h:30:10: fatal error: glib/galloca.h: No such file or directory
INFO: see full error report (y/[n])? y In file included from chafa_test.bac.generic.h:3, from chafa_test.bac.h:2, from chafa_test.bac.c:2: /usr/include/glib-2.0/glib.h:30:10: fatal error: glib/galloca.h: No such file or directory
What I'm trying to do is use libchafa in BaCon. Glib 2.0 libraries and Chafa are all complete on my system. Also the file galloca.h is present, but for some reason not found when compiling. However, I may be doing something wrong? This is my code: ' sudo apt install libchafa-dev libglib2.0-dev
PRAGMA LDFLAGS `pkg-config --cflags chafa glib-2.0` PRAGMA LDFLAGS `pkg-config --libs chafa glib-2.0`
PRAGMA INCLUDE <glib-2.0/glib.h> PRAGMA INCLUDE <chafa/chafa.h>
'PROTO chafa_symbol_map_new, chafa_symbol_map_add_by_tags, chafa_canvas_config_set_geometry, chafa_canvas_config_set_symbol_map, chafa_canvas_draw_all_pixels, chafa_canvas_build_ansi PROTO chafa_canvas_config_new
config = chafa_canvas_config_new()
PRINT config
Do you know what I may be missing here?
|
|
|
Post by agent725 on Dec 6, 2021 19:59:22 GMT 1
Have gotten a bit further (maybe...): ./chafa_test.bac.string.h ./chafa_test.bac.lex.c ./chafa_test.bac.functions.h ./chafa_test.bac.c ./chafa_test.bac.lex ./chafa_test.bac.generic.h ./chafa_test.bac.log ./chafa_test.bac.h ./chafa_test.bac.lex.exe ./chafa_test.bac.float.h Do you want to delete them ([y]/n)? Temporary files were deleted. Converting 'chafa_test.bac'... done, 24 lines were processed in 0.000 seconds. Creating lexical analyzer... done. Compiling 'chafa_test.bac'... cc `pkg-config --cflags chafa glib-2.0` -c chafa_test.bac.c /usr/include/chafa/chafa-version-macros.h:112:2: error: #error "CHAFA_VERSION_MIN_REQUIRED must be >= CHAFA_VERSION_1_0"
INFO: see full error report (y/[n])? y In file included from /usr/include/chafa/chafa.h:29, from chafa_test.bac.generic.h:4, from chafa_test.bac.h:2, from chafa_test.bac.c:2: /usr/include/chafa/chafa-version-macros.h:112:2: error: #error "CHAFA_VERSION_MIN_REQUIRED must be >= CHAFA_VERSION_1_0" 112 | #error "CHAFA_VERSION_MIN_REQUIRED must be >= CHAFA_VERSION_1_0" | ^~~~~ chafa_test.bac: In function 'main': chafa_test.bac:23:35: warning: character constant too long for its type 23 | PRINT 'Done.' | ^ make: *** [Makefile.bacon:6: chafa_test.bac.o] Error 1
My code is now: ' sudo apt install libchafa-dev libglib2.0-dev
PRAGMA LDFLAGS `pkg-config --libs chafa glib-2.0` PRAGMA OPTIONS `pkg-config --cflags chafa glib-2.0`
PRAGMA INCLUDE <glib-2.0/glib.h> PRAGMA INCLUDE <chafa/chafa.h>
'PROTO chafa_symbol_map_new, chafa_symbol_map_add_by_tags, chafa_canvas_config_set_geometry, chafa_canvas_config_set_symbol_map, chafa_canvas_draw_all_pixels, chafa_canvas_build_ansi PROTO chafa_canvas_config_new
config = chafa_canvas_config_new()
PRINT config PRINT 'Done.'
I'm using the following for reference: hpjansson.org/chafa/ref/chafa-using.html
|
|
|
Post by Pjot on Dec 6, 2021 21:02:17 GMT 1
Hi agent725, Those pesky Chafa version macro's are spoiling your compilation. I could make it work by setting the MAJOR and MINOR version manually. ' sudo apt install libchafa-dev libglib2.0-dev
PRAGMA OPTIONS -DCHAFA_MAJOR_VERSION=1 -DCHAFA_MINOR_VERSION=2 `pkg-config --cflags chafa` PRAGMA LDFLAGS `pkg-config --libs chafa`
PRAGMA INCLUDE <glib-2.0/glib.h> PRAGMA INCLUDE <chafa/chafa.h>
'PROTO chafa_symbol_map_new, chafa_symbol_map_add_by_tags, chafa_canvas_config_set_geometry, chafa_canvas_config_set_symbol_map, chafa_canvas_draw_all_pixels, chafa_canvas_build_ansi PROTO chafa_canvas_config_new
config = chafa_canvas_config_new()
PRINT config PRINT "Done."
Not sure why the problem happens, it might be some glitch in the packaged version of chafa. I have seen such problems before in the Ubuntu repos with libXaw3D for example. Anyway, hope you can proceed now BR Peter
|
|
|
Post by agent725 on Dec 6, 2021 21:07:13 GMT 1
Thank you so much! Works like a charm. I'm going to try to produce a little example using Chafa, which is a way to produce pretty images from UTF-8 characters on the command-line.
|
|
|
Post by Pjot on Dec 7, 2021 18:05:30 GMT 1
Great! I am curious to see it BR Peter
|
|
|
Post by agent725 on Dec 10, 2021 16:40:55 GMT 1
Getting further. However, I've got to admit the pointers thing has me challenged.
Right now I can produce some kind of output with the library, however, the result is most likely a pointer to the real result data, and I don't know how to get to that.
To get this far I have declared a variety of weird types that the library needs, and honestly don't quite know how this works yet.
' Get needed packages: sudo apt install libchafa-dev libglib2.0-dev
PRAGMA OPTIONS -DCHAFA_MAJOR_VERSION=1 -DCHAFA_MINOR_VERSION=2 `pkg-config --cflags chafa` PRAGMA LDFLAGS `pkg-config --libs chafa`
PRAGMA INCLUDE <glib-2.0/glib.h> PRAGMA INCLUDE <chafa/chafa.h>
PROTO chafa_symbol_map_new PROTO chafa_symbol_map_add_by_tags PROTO chafa_canvas_config_new PROTO chafa_canvas_config_set_geometry PROTO chafa_canvas_config_set_symbol_map PROTO chafa_canvas_new PROTO chafa_canvas_draw_all_pixels PROTO chafa_canvas_build_ansi
' Declares specific to libchafa DECLARE symbol_map TYPE ChafaSymbolMap * DECLARE config TYPE ChafaCanvasConfig * DECLARE canvas TYPE ChafaCanvas * DECLARE gs TYPE GString *
DECLARE pixels[36] TYPE guint8 FOR x = 0 TO 35 pixels[x] = 0 NEXT FOR x = 13 TO 25 pixels[x] = 255 NEXT
' Specify the symbols we want symbol_map = chafa_symbol_map_new() chafa_symbol_map_add_by_tags(symbol_map, CHAFA_SYMBOL_TAG_ALL)
config = chafa_canvas_config_new() chafa_canvas_config_set_geometry(config, 23, 12) chafa_canvas_config_set_symbol_map(config, symbol_map)
canvas = chafa_canvas_new(config)
' Draw pixels and build ANSI string PIX_WIDTH = 4 PIX_HEIGHT = 2 N_CHANNELS = 4
chafa_canvas_draw_all_pixels(canvas, CHAFA_PIXEL_RGBA8_UNASSOCIATED, pixels, PIX_WIDTH, PIX_HEIGHT, PIX_WIDTH * N_CHANNELS) result = chafa_canvas_build_ansi (canvas)
PRINT result
|
|
|
Post by Pjot on Dec 10, 2021 19:47:16 GMT 1
Hi agent725, I am following the example at hpjansson.org/chafa/ref/chafa-using.html. You can print struct members using the '->' construction also in BaCon, but you have to specify the type. So this works for me: ' Get needed packages: sudo apt install libchafa-dev libglib2.0-dev
PRAGMA OPTIONS -DCHAFA_MAJOR_VERSION=1 -DCHAFA_MINOR_VERSION=2 `pkg-config --cflags chafa` PRAGMA LDFLAGS `pkg-config --libs chafa`
PRAGMA INCLUDE <glib-2.0/glib.h> PRAGMA INCLUDE <chafa/chafa.h>
PROTO chafa_symbol_map_new PROTO chafa_symbol_map_add_by_tags PROTO chafa_canvas_config_new PROTO chafa_canvas_config_set_geometry PROTO chafa_canvas_config_set_symbol_map PROTO chafa_canvas_new PROTO chafa_canvas_draw_all_pixels PROTO chafa_canvas_build_ansi
CONST PIX_WIDTH = 3 CONST PIX_HEIGHT = 3 CONST N_CHANNELS = 4
' Declares specific to libchafa DECLARE symbol_map TYPE ChafaSymbolMap* DECLARE config TYPE ChafaCanvasConfig* DECLARE canvas TYPE ChafaCanvas* DECLARE gs TYPE GString*
DECLARE pixels[PIX_WIDTH * PIX_HEIGHT * N_CHANNELS] = \ { \ 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, \ 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, \ 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff \ } TYPE guint8
' Specify the symbols we want symbol_map = chafa_symbol_map_new() chafa_symbol_map_add_by_tags(symbol_map, CHAFA_SYMBOL_TAG_ALL)
config = chafa_canvas_config_new() chafa_canvas_config_set_geometry(config, 23, 12) chafa_canvas_config_set_symbol_map(config, symbol_map)
canvas = chafa_canvas_new(config)
chafa_canvas_draw_all_pixels(canvas, CHAFA_PIXEL_RGBA8_UNASSOCIATED, pixels, PIX_WIDTH, PIX_HEIGHT, PIX_WIDTH * N_CHANNELS) gs = chafa_canvas_build_ansi(canvas)
PRINT gs->str FORMAT "%s\n" HTH Peter Attachments:
|
|