This question was asked few times on stackoverflow. However, what I'm trying to do is a little bit different.
I'm trying to port python to QNX. Compiling all the source files and statically linking it to a "Hello World" script using python c API works.
I'm having problem with the struct module. I tried compiling struct into a shared library and placing it at the exec_prefix path specified by python. When I try to import it, It tries to load the module but it complains about unknown symbols.
It says something like
Unknown symbol: _PyUnicode_FormatAdvancedWriter referenced by _struct.so
I get a lot of unknown symbol errors like this. I included the header and source files of all these unknown symbols and it ends up throwing other unknown symbol errors.
I might be doing something completely wrong. Any ideas on how I can link them?
I'm answering my own question since I figured out the fix. If anyone else is having the same problem, you have to export all the symbols to the dynamic symbol table at link time. To do this, you have to pass a flag -E
to the linker i.e -Wl, -E
. That should solve the problem.
This is a qcc specific flag so if you're experiencing this problem in gcc, you can try passing --whole-archive flag to the linker.