CereLink icon indicating copy to clipboard operation
CereLink copied to clipboard

static lib exports too many symbols

Open cboulay opened this issue 8 years ago • 5 comments

Before figuring out the problem in #63 , I attempted to link to the static lib. This failed because the static lib exports too many symbols.

  • My application is a Qt application and its own inclusion of Qt headers collided with the exported Qt symbols from cbsdk_static.lib.
  • My application requires cbhwlib.h and its inclusion created clashes with the symbols in cbsdk_static.lib

I just did a nm -gU on cbsdk_static.a (in Mac) and it exports basically everything.

I'm not sure what the best way to handle this is. As far as I can tell, it's not straightforward to hide symbols during the creation of static libs, but it is possible. Is there any reason not to hide them?

cboulay avatar Feb 13 '17 01:02 cboulay

It is better to hide symbols that are not needed. It can be done through second answer. I am not sure if visibility is also available in clang.

dashesy avatar Feb 16 '17 05:02 dashesy

I checked the CMakeList file, this line is supposed to hide the symbols. At the time clang did not have an equivalent parameter, so it is disabled for APPLE build.

In your own application you can pass -Wl,--exclude-libs,ALL to avoid bringing in symbols from cbsdk_static.

dashesy avatar Feb 19 '17 22:02 dashesy

I think -Wl,--exclude-libs,ALL will only prevent these symbols from being exported in a new library that links cbsdk_static.a.

I solved the problem in Xcode at least. I followed the instructions here and I was able to eliminate the unwanted symbols. These settings can be set via cmake with the following:

SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES")
        SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_STRIP_STYLE "non-global")
        SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES")
        SET_TARGET_PROPERTIES(${LIB_NAME_STATIC} PROPERTIES XCODE_ATTRIBUTE_SEPARATE_STRIP "YES")

Also, I had to remove the STATIC_CBSDK_LINK compiler flag because it was causing the API symbols to remain hidden and not being set to default visibility.

I have these and many more cmake changes in my Production branch. I'll make one cumulative PR in the not-too-distant future.

cboulay avatar Feb 20 '17 04:02 cboulay

Oops. Problem not solved. With the reduced symbol exports, building cbmex fails because it cannot find cbGetAoutCaps as it is not set to visibility default. I'll comment out my xcode hacks for now.

Any desire to export symbols from cbhwlib explicitly?

cboulay avatar Feb 20 '17 04:02 cboulay

Could define something like DLL_EXPORT and set visibility of needed symbols to default. In general static libraries do not play well, is why e.g. Qt is almost never statically linked.

dashesy avatar Feb 20 '17 07:02 dashesy