Noob alert! I'm not exactly competent with C/C++ programming
Hi, I'm working on a C++ NodeJS addon, in which I'd like to use Cairo/Pango, but I'm having a number of linking issues. I can reasonably assume they're linking issues, as I had a similar one, calling a Cairo function. I was able to resolve it by adding -lcairo
to the g++
call, in my makefile. Unfortunately, this isn't working for Pango anymore.
Below is my Makefile
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))
SYS=-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/
NODE=-I/usr/include/node -I$(mkfile_dir)node_modules/node-addon-api/
INCLUDE=$(SYS) -I/usr/include/cairo -I/usr/include/pango-1.0
LIBS=$(shell pkg-config --cflags --libs cairo pango)
plugin.node: clean
g++ -shared -fPIC -o ./plugin.node lib.cpp -Wall -Wextra $(INCLUDE) $(LIBS)
clean:
$(if $(wildcard ./*.node), rm *.node)
The LIBS
variable came from a SO post advising against using -l...
options, and instead using pkg-config
to locate them. The C++ code is nothing extraordinary, but for completeness, it's below.
#include <cairo.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
struct Canvas {
uint16_t width, height;
cairo_surface_t* surface;
cairo_t* ctx;
};
// ...
PangoLayout *layout = pango_cairo_create_layout(canvas->ctx);
PangoFontDescription *desc = pango_font_description_new();
pango_layout_set_text (layout, "Test String", 11);
pango_font_description_set_size(desc, 10);
// ...
The compilation succeeds, with only warnings about unused variables, however, when attempting to load the module in NodeJS, the following error appears:
/usr/bin/node: symbol lookup error: /.../plugin.node: undefined symbol: pango_cairo_create_layout
Edit
When running pkg-config --cflags --libs cairo pango
, the following output is produced:
-pthread -I/usr/include/pango-1.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng16 -lcairo -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz
pkg-config --cflags --libs cairo pango
andreadelf -d plugin.node
? – Employed Russianlibpangocairo-1.0.so.0
is being picked up at runtime, and does that version definepango_cairo_create_layout
. You can answer the first question by runningnode
withLD_DEBUG=libs
environment variable set, and the second by runningnm -D /path/to/libpangocairo-1.0.so.0 | grep ' pango_cairo_create_layout'
. – Employed RussianLD_DEBUG=libs
set. gist.github.com/J-Cake/c8ef8e4c5f54d4a160d37a4954882225 – Jacob Schneider