문제

I'm trying to reuse an old static library built with Linux GCC 2.95.2. I'm using a recent compiler (GCC 4.6) from a 32bit Ubuntu distro. The library is written in C++. I have problems linking against the functions which are encapsulated in classes.

I guess that the naming of the symbols has changed.

http://www.qnx.com/developers/docs/6.3.2/momentics/compatibility/about.html#C++_code: GCC 2.95.3 (from 6.2.1 or 6.3) and GCC 3.3.5 use different C++ ABIs and have different name mangling. As a result, you can't link C++ binaries (objects, executables, libraries) built with GCC 2.95.3 with binaries built with GCC 3.3.5.

The error output of ld is:

undefined reference to `foo1::Bar()' (class foo1; Member Bar)

With the tool mn the symbols could be read out. The matching symbol is named in a different way:

Bar__4Foo1

Question: Is there a way the rename the symbols in the library file? Or can I force ld to accept the old naming format?

도움이 되었습니까?

해결책

I guess that the naming of the symbols has changed.

Correct.

What you are missing is that the naming has changed for a reason, namely code produced by g++ 2.95 and g++ 3.3 is ABI incompatible. If you were allowed to link two objects compiled with these compilers together, all you'd get is unexplainable crashes.

By changing the name mangling, GCC developers have saved you the trouble of debugging such crashes.

Is there a way the rename the symbols in the library file?

There is, but if you succeed with that, you'll end up with said crashes, so don't shoot your foot off.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top