Page 1 of 1

wxWidgets in OSX shared library (fvisibility=hidden)

Posted: Tue Dec 04, 2018 11:18 am
by weglimir
Hello,

I have a problem with building wxWidgets for OSX and hidding all the symbols. I'm trying to build shared library which will be responsible for just showing some custom dialogs - but this library has to work in independent way. The problem is that application have to work for Windows and OSX, and have to work with wxWidgets application and other applications (kind of plug-in environment). My relations:
1) wxWidgets based application <-> Shared SO/DLL (plug-in) <-> shared library with wxWidgets dialogs(dll/so).
2) Other standalone app without wxWidgets <-> Shared SO/DLL (plug-in) <-> shared library with wxWidgets dialogs(dll/so).

Now for Windows I've followed example: https://github.com/wxWidgets/wxWidgets/ ... amples/dll and everything works like a charm. Now for OSX I have huge problems to hide Objective C symbols. The moment shared library with dialogs is loaded I have following errors:

Code: Select all

objc[24994]: Class wxNSAnimationDelegate is implemented in both /Users/imac/Projects/GPE_trunk/trunk/GPESA/build/Debug/GConManager.app/Contents/MacOS/GConManager and /usr/local/lib/libgpe_gui_elements.so. One of the two will be used. Which one is undefined.


From this moment applications acts very strange, like it can't be closed using window "x" button. I've tried everything to hide those symbols, my configure:

Code: Select all

../configure --enable-debug --with-osx_cocoa --with-zlib=builtin --without-libiconv --without-liblzma --disable-shared --disable-mediactrl --enable-universal_binary=i386,x86_64 --with-macosx-version-min=10.7 --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk --disable-visibility CFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG" CXXFLAGS="-stdlib=libc++ -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden" OBJCXXFLAGS="-stdlib=libc++ -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden" OBJCXXFLAGS="-stdlib=libc++ -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden" OBJCFLAGS="-stdlib=libc++ -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden" LDFLAGS="-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden" --prefix="$(pwd)"


Which is passed correctly during build, but still doesn't work for me. Building shared library with dialogs also contains such flags. While building either the wxWidget application or shared library with dialogs, I was trying to pass -Xlinker -x, and after that command:

Code: Select all

nm build/Debug/MyApp.app/Contents/MacOS/MyApp | grep -i wx

Doesn't return any symbols, so I'm kind of lost what is going on. So how can I hide objective C related symbols?

Re: wxWidgets in OSX shared library (fvisibility=hidden)

Posted: Tue Dec 04, 2018 3:47 pm
by ONEEYEMAN
Hi,
Does wxWidgets build correctly?
What was you configure line for building library?

Also, just curious - what is the reason for hiding the symbols?

Thank you.

Re: wxWidgets in OSX shared library (fvisibility=hidden)

Posted: Tue Dec 04, 2018 4:02 pm
by weglimir
ONEEYEMAN wrote:Hi,
Does wxWidgets build correctly?

Yes, of course. Here are the example flags:

Code: Select all

/Users/imac/Projects/wxWidgets-3.1.0/build-debug/bk-deps /usr/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.7 -c -o stclib_ScintillaWX.o  -D__WXOSX_COCOA__      -DWXBUILDING -I/Users/imac/Projects/wxWidgets-3.1.0/build-debug/src/tiff/libtiff -I../src/tiff/libtiff -I../src/jpeg -I../src/png -I../src/zlib -I../src/regex  -I../src/stc/scintilla/include -I../src/stc/scintilla/lexlib -I../src/stc/scintilla/src -D__WX__ -DSCI_LEXER -DLINK_LEXERS -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wno-deprecated-declarations -D_FILE_OFFSET_BITS=64 -I/Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/wx/include/osx_cocoa-unicode-static-3.1 -I../include -g -O0 -arch i386 -arch x86_64 -stdlib=libc++ -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden -fno-common  ../src/stc/ScintillaWX.cpp


ONEEYEMAN wrote:What was you configure line for building library?

I'm not using configure, but my own build system, but more or less it looks like this, compilation:

Code: Select all

clang++ -m64 -O2 -mmacosx-version-min=10.7 -std=c++1y -stdlib=libc++ -I../../ -I/usr/local/include/libusb-1.0/ -I//usr/local/Cellar/boost/1.64.0_1/include/ -fPIC -D_REENTRANT -DRELEASE -fvisibility=hidden -Wno-inconsistent-missing-override -MMD -DNDEBUG  -I/Users/imac/Projects/wxWidgets-3.1.0/build-release/lib/wx/include/osx_cocoa-unicode-static-3.1 -I/Users/imac/Projects/wxWidgets-3.1.0/include/ -D_FILE_OFFSET_BITS=64 -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ -Wno-potentially-evaluated-expression -Wno-inconsistent-missing-override -DNDEBUG -DwxDEBUG_LEVEL=0 -c  ..//init/GPEGUIElements.cpp -o ..//init/GPEGUIElements.o


Linking:

Code: Select all

clang++ -shared -Xlinker -x -m64 -mmacosx-version-min=10.7 -stdlib=libc++ -std=c++1y -Xlinker -headerpad -Xlinker 578 -fvisibility=hidden -Wl,-rpath,/usr/local/lib -o xos/x64/libgpe_gui_elements.so ..//dialogs/PresetSaveAsDialog.o ..//GConDialogContext.o ..//init/GPEGUIElements.o -L/usr/local/Cellar/boost/1.64.0_1/lib/ -Bstatic /usr/local/Cellar/boost/1.64.0_1/lib/libboost_log-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_system-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_program_options-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_filesystem-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_log_setup-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_thread-mt.a /usr/local/Cellar/boost/1.64.0_1/lib/libboost_regex-mt.a /usr/local/lib/libusb-1.0.a -L../../GPE/build/xos/xFAT/ -lgpe -L../../GCon/build/xos/xFAT/ -lgcon  -Wl,-framework,IOKit -Wl,-framework,CoreFoundation -lobjc -L/Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_osx_cocoau_xrc-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_osx_cocoau_qa-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_baseu_net-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_osx_cocoau_html-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_osx_cocoau_adv-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_osx_cocoau_core-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_baseu_xml-3.1.a /Users/imac/Projects/wxWidgets-3.1.0/build-debug/lib/libwx_baseu-3.1.a -framework WebKit -lexpat -lwxregexu-3.1 -lwxtiff-3.1 -lwxjpeg-3.1 -lwxpng-3.1 -lwxzlib-3.1 -lpthread


ONEEYEMAN wrote:Also, just curious - what is the reason for hiding the symbols?

Well, it is plug-in kind of environment, it is very common to hide symbols, as you never know what other plugins symbols can contain. There are two use cases:
1) wxWidgets executable loads shared object, which is linked (and uses) wxWidget dialogs.
2) any other executable loads shared object, which is linked (and uses) wxWidget dialogs.

Thus when using wxWidget executable and shared object which same symbols, there are errors, and application acts very strange - definitely there are problems with symbol missmatch. This is medium size project in general (150k+ lines of code) with other GUI frameworks as well, so keeping it isolated would be perfect. Such approach works perfectly on Windows (on Windows symbols are hidden by default).

Thank you in advance.