How to export symbols from a shared library

后端 未结 3 1068
梦如初夏
梦如初夏 2020-12-17 03:16

I created a shared library (*.so) using the *.o object code files (C source code) using RVDS compiler on Windows Host.

I link this shared o

3条回答
  •  别那么骄傲
    2020-12-17 04:19

    1. You do not need to export symbols with gcc, as it exports all symbols by default; RVDS may or may not do the same, however. Check your RVDS compiler documentation (try configuring it for 'Relocatable ELF' output?)

    2. Shared libraries on Linux must be relocatable, as the base address is determined at runtime. Generating position-independent code is ideal, as it reduces the amount of work needed to relocate the library. If your library is not relocatable it will crash (in other words, don't strip relocation information from your object files before making the dynamic library). Symbols are resolved to addresses at runtime after the base address is selected and internal references are relocated.

    3. With static libraries, all symbol resolution, relocation, and assignment of load addresses happens at compile time.

    My only guess would be that somehow, the code your compiler is putting out is not relocatable at runtime. It's a mystery to me how that would happen without breaking static libraries as well, though...

    If you're generating a static library and shared library directly from RVDS, one option would be to try to convert that static library to a shared library:

    gcc -shared -o libfoo.so libfoo.a
    

    If this helps, then RVDS's shared library linker (or its configuration) is likely broken.

提交回复
热议问题