boost distributed with closed source library
I have an application that needs to use a certain closed source C++ API. This API is distributed with some bits of Boost, binary library files and all. I like to use Boost in my own code. I can't just use their version of Boost since they did not distribute all the parts of Boost I need. How should I proceed? The target platform is linux, eventually Windows as well.
- I won't pass Boost objects across the API boundary.
- I can com开发者_运维百科pile things to object files so that my code uses my boost headers, and the API's code uses its Boost headers. This part seems straightforward.
- What I don't get: how to link my code to my Boost library files, and API's code to its Boost library files. Do I need to compile my own wrapper around the API -- a wrapper whose headers do not include Boost -- to a dynamic library?? (This is the only way I can think of to do the linking. The symbols in the API's Boost library files should be identical to the symbols in my Boost library files. I have to do the linking in two stages, no? The only way I can link one piece of the program without the rest is by making a dynamic library, no?)
A given executable can only have one piece of code for each symbol. So if their library uses symbol foo from boost v. 1 and you use the same symbol from boost v. 2, then you will get a clash. There's no easy way to get rid of this clash without changing the symbol. It should be possible to use dynamic execution if you were able to compile the boost code into a dynamic library, but this seems like it would be overkill.
Since, in C++, a symbol is mangled with its class/namespaces, you could also change one of these to get the symbol to change.
If you are only using the header-only boost libraries, you can just build your code separately from the code that links against the other libraries.
Which boost libraries are you using?
How does the api link with the boost library they used? They deploy a boost-##.so with it, or it was statically link?
So, please run "objdump -T api.so | grep boost" in your api .so to check if the api exposes the Boost.
Also, it is possible that they have renamed the boost namespace like the user chrisaycock mentioned. Use the c++filt command to have a closer look at the symbols you found with "objdump -T api.so | grep boost".
If it was statically linked and the boost symbols weren't exposed ( or were renamed ) then you can use boost at your code without concerning the API's boost.
If boost is really exposed, I recommend to just try using boost. To your code using boost, probably a clash won't happen. If it happens, you may compile a new boost and change your namespace name. Just run a replace-all script replacing "namespace boost" for something like "namespace boost_1_46".
精彩评论