Ableton / LinkKit

iOS SDK for Ableton Link, a new technology that synchronizes musical beat, tempo, and phase across multiple applications running on one or more devices.
http://ableton.github.io/linkkit
Other
147 stars 10 forks source link

Duplicate symbols when using Boost in own project #11

Closed markusthegeek closed 8 years ago

markusthegeek commented 8 years ago

I am getting duplicate symbol errors due to using Boost in our app when linking with Link. Workaround is to remove the reference to $(BOOST_ROOT)/libs/system/src/error_code.cpp but this could lead to problems with different Boost versions.

duplicate symbol __ZN5boost6system15system_categoryEv in: /Users/USER/Library/Developer/Xcode/DerivedData/iPRODUCT-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iPRODUCT.build/Debug-iphoneos/iPRODUCT2.build/Objects-normal/armv7/error_code.o /Users/USER/NIBuild/PRODUCT/iPRODUCT/iPRODUCT/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) duplicate symbol __ZN5boost6system16generic_categoryEv in: /Users/USER/Library/Developer/Xcode/DerivedData/iPRODUCT-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iPRODUCT.build/Debug-iphoneos/iPRODUCT2.build/Objects-normal/armv7/error_code.o /Users/USER/NIBuild/PRODUCT/iPRODUCT/iPRODUCT/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) duplicate symbol __ZN5boost6system6throwsE in: /Users/USER/Library/Developer/Xcode/DerivedData/iPRODUCT-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iPRODUCT.build/Debug-iphoneos/iPRODUCT2.build/Objects-normal/armv7/error_code.o /Users/USER/NIBuild/PRODUCT/iPRODUCT/iPRODUCT/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) ld: 3 duplicate symbols for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

gatzsche commented 8 years ago

It seems that LINK SDK uses boost as well your application. This leads to conflicts.

@Linkteam: In Xcode build settings you can rename symbols while building the library. Add something like this to "Other C Flags": -DSomeBoostSymbol=ALESomeBoostSymbol

@Markus: As long Link SDK does not use renamed symbols, you can rename it in your application too.

Am 23.02.2016 um 19:06 schrieb markusthegeek notifications@github.com:

I am getting duplicate symbol errors due to using Boost in our app when linking with Link. Workaround is to remove the reference to our local error_code.h file but this could lead to problems with different Boost versions.

duplicate symbol ZN5boost6system15system_categoryEv in: /Users/markus.krieg/Library/Developer/Xcode/DerivedData/iMaschine-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iMaschine.build/Debug-iphoneos/iMaschine2.build/Objects-normal/armv7/error_code.o /Users/markus.krieg/NIBuild/Maschine/iMaschine/iMaschine/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) duplicate symbol __ZN5boost6system16generic_categoryEv in: /Users/markus.krieg/Library/Developer/Xcode/DerivedData/iMaschine-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iMaschine.build/Debug-iphoneos/iMaschine2.build/Objects-normal/armv7/error_code.o /Users/markus.krieg/NIBuild/Maschine/iMaschine/iMaschine/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) duplicate symbol ZN5boost6system6throwsE in: /Users/markus.krieg/Library/Developer/Xcode/DerivedData/iMaschine-fnrscsrtzxoykzcvqebykufwruof/Build/Intermediates/iMaschine.build/Debug-iphoneos/iMaschine2.build/Objects-normal/armv7/error_code.o /Users/markus.krieg/NIBuild/Maschine/iMaschine/iMaschine/LinkKit-1.0.0/lib/libABLLink.a(error_code.o) ld: 3 duplicate symbols for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

— Reply to this email directly or view it on GitHub https://github.com/Ableton/LinkKit/issues/11.

markusthegeek commented 8 years ago

@gatzsche, thanks for the hint. I would prefer to work without symbol redefines on our side. So I will re-add my Boost CPP file as soon as you guys have added a fix to your lib.

brs-ableton commented 8 years ago

@markusthegeek Yes we include boost::system in the static library, which is a convenience for non C++ devs but is a problem if you use boost in your app. The only reason we need boost::system at all is because it's a dependency of boost::asio, which we use for networking. We're in the process of switching to asio-standalone, which is a version of asio that does not depend on boost at all in order to remove this dependency. This will come in a future update. For now I can tell you that we use boost 1.59, so if you use a compatible version then you can safely remove the error_code.cpp file from your build.

@gatzsche It doesn't seem so easy to hide these symbols. Symbol visibility is only handled at link time, which doesn't happen when building a static library. Tools like objcopy that work on osx or linux don't work for ARM. The preprocessor approach you suggested is difficult to make work for the boost symbols because of the namespacing.

michaeltyson commented 8 years ago

@brs-ableton We use some popular third-party libs in the Audiobus SDK (actually, technically first-party, because I wrote them, but they're external to Audiobus =)), so we have the same renaming requirements - otherwise you get duplicate symbol build errors if you use those other libs. The symbol renaming using the -D flag does indeed work, verifiable by listing the symbols in the built library archive using nm. I can see how C++ namespacing may be a PITA; it's probably just a matter of working out the -D syntax, though.

brs-ableton commented 8 years ago

@michaeltyson It definitely works but the problem is that with C++ the symbols that show up in the binary have mangled namespace paths. When you redefine in the pre-processor, you're not remapping these output symbols but the identifiers in the code, which are then concatenated and mangled to generate the symbol in the library. I can't redefine __ZN5boost6system16generic_categoryEv with the pre-processor, I have to redefine boost or system or generic_category. And some of these identifiers can't be redefined and still build correctly (in particular, the boost library won't build out of the box if the string boost is redefined). With enough effort I'm sure we could make it work but we have already removed the boost dependency from our main development branch so we're going to focus on getting that released rather than hacking around this.

michaeltyson commented 8 years ago

Ouch, that's horrible! Yeah, okay, I stand both horrified and corrected =)

brs-ableton commented 8 years ago

LinkKit 2.0.0 beta no longer has a boost dependency.