How to hidden all symbols(function name etc) use cmake build system?

hi:
I am trying to build juce with static library, and our app link the library. how can we remove symbol names from cmake?

To the best of my knowledge, there’s not really any way of changing symbol visibility in a static lib, beyond the normal internal/external linkage that is included in the core language (using keywords like static and extern).

Please provide more information about the problem. Why do you need to hide the symbols? Are you trying to desymbolicate the library for a release build so that third parties can’t see your function names? Are you trying to build multiple copies of JUCE into your application without encountering symbol collisisons?

yes. I linked the static library and can be found symbols on command nm on the binary, so I am asking desymbolicate the library for a release build.

I am afraid Reverse Engineering if not removed(hide) them.

You could try adding -s to your link flags to strip symbols.

One way of doing this is to supply -D CMAKE_MODULE_LINKER_FLAGS=-s when configuring your CMake project.

Another option is to add target_link_options (target PUBLIC "-s") to your plugin targets.

In both cases, you should only do this when you know the linker supports the -s flag.

When I build a VST3 with this flag enabled, I see that the only public/defined symbols remaining in the nm output are the GetPluginFactory functions, along with bundleEntry and bundleExit. There’s also a public repostCurrentNSEvent function that I think should probably be hidden - I’ll investigate a bit further and make that change in JUCE if it looks like a good idea.

All other public symbols are undefined symbols that are loaded from system libraries. No function signatures from JUCE or user code are made public.

I’ve made this change on the develop branch, hiding the repostCurrentNSEvent function:

With this change in place, a stripped JUCE VST3 plugin should only contain symbols for the VST3 entry-points, and any functions that must be loaded from system libraries.

Hi Reuk,

On macOS the target_link_options (target PUBLIC "-s") does not work anymore, I get the warning: ld: warning: option -s is obsolete and being ignored.

What is now the suggested way to strip audio plugins on macOS? Thank you.

I’m just calling in my deployment script:

/usr/bin/strip -x PluginName.vst3/Contents/MacOS/PluginName

On the final binary

Ok, nice, I’ve done the same in my installer script and it works perfectly. What about Windows?

I’m building with Clang on Windows, so I’m using:

C:\Program Files\LLVM\bin\llvm-strip.exe -x -s filename 

Not sure what’s the flow for MSVC

1 Like