Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static lib exports too many symbols #64

Open
cboulay opened this issue Feb 13, 2017 · 5 comments
Open

static lib exports too many symbols #64

cboulay opened this issue Feb 13, 2017 · 5 comments

Comments

@cboulay
Copy link
Collaborator

cboulay commented Feb 13, 2017

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?

@dashesy
Copy link
Collaborator

dashesy commented Feb 16, 2017

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
Copy link
Collaborator

dashesy commented Feb 19, 2017

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.

@cboulay
Copy link
Collaborator Author

cboulay commented Feb 20, 2017

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
Copy link
Collaborator Author

cboulay commented Feb 20, 2017

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?

@dashesy
Copy link
Collaborator

dashesy commented Feb 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants