boost distributed with closed source library
Asked Answered
L

3

8

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 compile 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?)
Lamdin answered 28/1, 2011 at 4:36 Comment(7)
I have to work with a third-party's closed-source library as well. They distributed their own (really old) version of Boost with the library. Fortunately, they renamed their Boost library, like BoostSystem_x86-64_redhat_gcc41_mdi instead of boost_system. Somehow, my code actually builds.Rutger
see #2908382Sphery
@Rutger Are you using Activ? I have the same filename! But I suspect the symbols in that file have the same name as the ones in my version of boost, which means my Boost would be linking to Activ's boost... @Sphery I still haven't gotten an answer to this linking issue... (even if it works, I'm a little afraid to hope it will keep working..)Lamdin
Yes, Activ it is! I just link both their Boost and my Boost. I'm not sure what gcc is doing to resolve any conflicts, but the system works.Rutger
Which parts of boost are you using?Bifid
The ideal solution to this is that both your third party library and your library compile boost into dynamic libraries with the version baked in the filename.Broome
I'm linking against your previous question to make it easier to find: https://mcmap.net/q/1226865/-closed-source-library-includes-boost-distribution/478288Rutger
O
1

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.

Oakleil answered 16/6, 2011 at 17:29 Comment(0)
B
0

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?

Bifid answered 2/2, 2011 at 1:7 Comment(1)
Header-only or not, this is just asking to violate the ODR, as different versions of Boost will have different definitions of various types and functions, both in namespace boost.Tidewaiter
C
0

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".

Concenter answered 24/6, 2011 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.