Home | News | Documentation | Download

Cling repl syntax to add libraries & compilation flags?


#1

I’m merely using cling as a c++ coding tool (on Ubuntu 18)… but I’m not finding a way to feed it .a or .so libraries.
[Yes, I’ve looked – but so far have not found this sufficiently clearly laid out. Example?]

?


#2

whereis libfltk
gives me:
libfltk: /usr/lib/x86_64-linux-gnu/libfltk.a /usr/lib/x86_64-linux-gnu/libfltk.so
and whereis libX11
libX11: /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libX11.a
.L works on the .so versions but not the .a libraries.
If I try to run a perfectly good example program:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,180);
Fl_Box *box = new Fl_Box(20,40,260,100,“Hello, World!”);
box->box(FL_UP_BOX);
box->labelsize(36);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
Okay – If I only .L the .so libraries, cling remains happy.
If I then enter the program line by line
there’s no response.

Ah? I’ll need to define the program as a function
& then run the function?
[These no-brainer things can be bewildering without clear examples!]


#3

Okay okay:
[cling]$ int y;
[cling]$ .L /usr/lib/x86_64-linux-gnu/libfltk.so
[cling]$ .L /usr/lib/x86_64-linux-gnu/libX11.so
[cling]$ #include <FL/Fl.H>
[cling]$ #include <FL/Fl_Window.H>
[cling]$ #include <FL/Fl_Box.H>
[cling]$ int furr() {
[cling]$ ? Fl_Window *window = new Fl_Window(300,180);
[cling]$ ? Fl_Box *box = new Fl_Box(20,40,260,100,“Hello, World!”);
[cling]$ ? box->box(FL_UP_BOX);
[cling]$ ? box->labelsize(36);
[cling]$ ? box->labelfont(FL_BOLD+FL_ITALIC);
[cling]$ ? box->labeltype(FL_SHADOW_LABEL);
[cling]$ ? window->end();
[cling]$ ? window->show();
[cling]$ ? return Fl::run();
[cling]$ ? }
[cling]$ y = furr();

Works!
[There are different forms of fltk “window->show()” depending on whether or not we want it to take arguments from the command line.]