I also tried with a build from the default branch and it seems to work:
$ g++ -c -I/usr/include/hdf5/serial -I/usr/include/suitesparse -fPIC -I/home/osboxes/usr/include/octave-7.0.0/octave/.. -I/home/osboxes/usr/include/octave-7.0.0/octave -I/home/osboxes/usr/include -pthread -fopenmp -g -O2 ../examples/code/embedded.cc -o /tmp/oct-CNPWgH.o
$ g++ -shared -I/usr/include/hdf5/serial -I/usr/include/suitesparse -I/home/osboxes/usr/include/octave-7.0.0/octave/.. -I/home/osboxes/usr/include/octave-7.0.0/octave -I/home/osboxes/usr/include -pthread -fopenmp -g -O2 -rdynamic -o embedded.so /tmp/oct-CNPWgH.o -fPIC -L/home/osboxes/usr/lib -L/home/osboxes/usr/lib -L/home/osboxes/usr/lib/octave/7.0.0 -loctinterp -loctave
$ LD_PRELOAD=./libinterp/.libs/liboctinterp.so:./liboctave/.libs/liboctave.so python embedded.py
GCD of [10, 15] is 5
embedded.py:
import ctypes
shared_lib = ctypes.CDLL('./embedded.so')
shared_lib.main()
It doesn’t seem to matter if this diff is applied or not:
diff -r 7854d5752dd2 examples/code/embedded.cc
--- a/examples/code/embedded.cc Wed Feb 10 10:10:40 2021 -0500
+++ b/examples/code/embedded.cc Thu Feb 18 10:25:11 2021 +0100
@@ -4,6 +4,11 @@
#include <octave/parse.h>
#include <octave/interpreter.h>
+extern "C"
+{
+int main(void);
+}
+
int
main (void)
{
Also works with the Octave 5.2.0 distributed with Ubuntu 20.10. But I need to preload the libraries (not sure why):
$ g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-TC4r0Y/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security /usr/share/doc/liboctave-dev/examples/embedded.cc -o /tmp/oct-RhNJBU.o
$ g++ -shared -Wdate-time -D_FORTIFY_SOURCE=2 -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-TC4r0Y/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -rdynamic -fPIC -Wl,-Bsymbolic-functions -Wl,-z,relro -o embedded.so /tmp/oct-RhNJBU.o -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/octave/5.2.0 -loctinterp -loctave
$ python embedded.py
error: /usr/lib/x86_64-linux-gnu/octave/5.2.0/oct/x86_64-pc-linux-gnu/PKG_ADD: /usr/lib/x86_64-linux-gnu/octave/5.2.0/oct/x86_64-pc-linux-gnu/__init_gnuplot__.oct: failed to load: /usr/lib/x86_64-linux-gnu/octave/5.2.0/oct/x86_64-pc-linux-gnu/__init_gnuplot__.oct: undefined symbol: _ZTI18handle_cdef_object
GCD of [10, 15] is 5
$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liboctinterp.so:/usr/lib/x86_64-linux-gnu/liboctave.so python embedded.py
GCD of [10, 15] is 5