I'm trying to create a shared library (.so file I believe) for use with a Python script using SWIG. The program will compile and run fine on it's own, but when I create the shared library and try to import the library using, I get an error like so:
ImportError: /path/to/file.so: undefined symbol: _ZNK4Glib5Error4whatEv
I checked out the symbol using c++filt to see what was causing the issue:
c++file _ZNK4Glib5Error4whatEv ---> Glib::Error::what() const
I'm not really sure what's causing this error. I tried using pkg-config --cflags with glib-2.0 as the first library, but that didn't solve the issue. I read on some other posts about linking the LD path, but I'm not sure what that is or how to do it.
Additionally, I tried including an extra header in my CPP file
#include <glib/gerror.h>
But that didn't make a different either. Here are the steps I took before things didn't work:
Compile program and save *.o files using
CPPFLAGS := i_include/ -rdynamic -Wall -ggdb3 -std=c++11 $(shell pkg-config --cflags gtk+-3.0 gtkmm-3.0 ... g++ -c $(CPPFLAGS) $^ -o $@ -rdynamic //(This line executes for many files^)
Move to directory that contains the Python file that I'd like to call CPP funcitons from and create a .i file as an interface for SWIG/Python.
Run
swig -python file.i
Run
g++ -shared /path/to/files.o -o newFile.so
Import module in Python and try to run Python script, but get import error instead.
It seems like the only place I even have a call to Glib::Error is when I'm trying to open a file that doesn't exist, but like I said, the program compiles and runs fine. If there's any information that I left out, comment and I'll add it!
UPDATE: I ran ld -o outifle.o /path/to/files.o
and I hundreds of undefined reference errors (it look like every function call was undefined). Did I use ld
wrong?
UPDATE: @AsteroidsWithWings was patient enough to suggest a solution that worked for other users, where linking the libraries comes at the end of a command. Unfortunately, this did not solve my problem. I placed the linking for every relevant Make directive at the end and repeated the below process.
UPDATE: @PhilipWithnall suggested that I run pkg-config --cflags --libs ...
(addition of --libs flag). After recompiling and running again, this unfortunately did not solve my problem.