简体   繁体   中英

Static and shared libraries linker error

I'm using NDK (native compiler tools for android). So, the situations looks like this:

Static boost → Shared helpers
                       ↓
                  Shared Game

Helpers is some shared library for game developing. shared game is a library which is included by java code (loaded as native library). Helpers lib is using boost inside, the linker is fine here. Shared game uses boost through helpers api but compilation fails.

Linker can't resolve some symbols from boost_system library. So, I did like this:

Static boost → Shared helpers
     |                  ↓
     +----------- → Shared Game

And now it compiles fine. What's wrong? I thought that I can link boost once into helpers and use them inside shared game.

Nothing is wrong. As you said you want the shared game to use only shared helpers API which is exported by shared helpers dynamic library. Your mistake is that shared game still relies on some bare Boost API which is obviously not exported by shared helpers . That's why you have to link Boost explicitly to shared game too, so that these Boost symbols are resolved properly.

If you want to fully abstract from Boost API and eliminate this dependency, then you'd have to wrap this Boost API (which you require in shared game ) by expanding shared helpers (and of course don't forget to export this wrapped API from shared helpers too).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM