The issue is somewhat similar to this question but the accepted answer does not really propose a solution or workaround.
In our project, we have a dylib and the main
Well, even though I have accepted an answer it did not solve all problems. So I'm writing down the solution which did work in the end.
I made a small tool for post-processing the object files and marking the local symbols as UNDEF
. This forces the linker to use definitions from libstdc++
and not local ones from the file. The basic approach of the tool is:
LC_SYMTAB
command__ZTISt9bad_alloc
)N_UNDF|N_EXT
.(I also made a similar implementation for ELF)
I post-process any file that's using std exceptions, either for throwing or for catching. To make sure the file list does not go stale, I added a post-link check for unwanted local symbols using nm
.
This seems to resolve all the problems I've had so far.