gtk2- gtk3 error when calling ofSystemLoadDialog ->seems related with ofxOpenCV, and opencv dependencies on gtk2

hi everyone,

i have a problem in my fork of lpmt, using of from github.

it compiles well, and work also quite well except when i call ofSystemLoadDialog to load a video or image, the app crashes with the error

Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported

i didn’t have this issue with OF 0.8.3.
is there a new way to call a system dialog in the last version of OF? or am i missing something obvious again?

thanks for your replies.

edit : forgot to mention that i am running on lubuntu 14.04, and its ofSystemLoadDialog that i meant, bad point for me not rereading post before submitting :slight_smile:

i can reproduce the same issue on ubuntu 14.10, with latest OF from git.

going a bit further deep in ofSystemUtils.cpp, the crash appears with the call of gtk_init().

don’t really understand what happens there…
i checked the make command, and it’s gtk3 that is linked and not gtk2…
and in ofSystemUtils the defined GTK_MAJOR_VERSION is >=3 (i checked that by looking how OPEN_BUTTON was defined), so evertything seems to use gtk3…

here is an extract of codeblacks build log :

`-------------- Build: Debug in lpmtX (compiler: GNU GCC Compiler)---------------

Running command: make -f Makefile Debug
HOST_OS=Linux
HOST_ARCH=x86_64
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk+-3.0 libmpg123 
Compiling OF library for Debug
make -C ../../../libs/openFrameworksCompiled/project/ Debug PLATFORM_OS=Linux ABIS_TO_COMPILE_DEBUG=""
HOST_OS=Linux
HOST_ARCH=x86_64
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk+-3.0 libmpg123 
make[1]: Entering directory `/home/acryl/mapping/dev/openFrameworks/GIT_1412/openframeworks/libs/openFrameworksCompiled/project'
HOST_OS=Linux
HOST_ARCH=x86_64
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk+-3.0 libmpg123 

HOST_OS=Linux
HOST_ARCH=x86_64
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk+-3.0 libmpg123 
Done!

I found this link here that explains how it’s bad to have gtk2 and gtk3 linked in the same program, but i don’t understand what i can do about it since i don’t even understand where there is a link to a gtk2 lib…

To go a bit further (or trying to), i made a new project using PG, with just the foolowing in main :

 ofAppGlutWindow window;
 ofSetOpenGLVersion(1,4);
 ofSetupOpenGL(&window, 1024, 768, OF_FULLSCREEN);    ofRunApp(new ofApp());

and in testApp.cpp just the following in mousePressed :

ofFileDialogResult res = ofSystemLoadDialog();
cout<< res.getPath()<<endl;

it does work without GTK error. So if there is a gtk2 symbol used, it’s definitly not due to ofSystemLoadDialog.

i then copied the addons.make of my app to this test project
recompile, it crashes.

after a bit of struggling removing addons one by one and testing, it seems that the guilty addon is ofxOpenCv.
Simple opendialog test crashes when ofxOpenCV is in addons.make, but works fine when ofxOpenCV is removed from addons.make

i think i’m loosing my mind :frowning:

edit : since OF dependencies include libopencv-dev which depends on libopencv-highgui-dev which depends on libgtk2.0-dev, it seems to make sense that if you link ofxOpenCV, you link gtk2 as well…

But in OF 0.8.3 install_dependencies.sh script, libopencv-dev is not installed, in the current github, install_dependencies.sh install libopencv-dev, that may explain why i didn’t run into this problem using OF 0.8.3.
i don’t see any way to work around this, maybe removing libopencv-dev and dependencies and rebuilding OF?
Can anyone try to reproduce this, as it seems annoying not to use opencv with openframeworks because of gtk incompatibilities?
Or maybe there is a way to force the use of GTK2 in openframeworks core without recompiling all OF?

i am opening an issue on github.

OF detects the gtk version installed and can use 2 or 3, probably uninstalling the dev pkg of 3 will solve the problem:

sudo apt-get remove libgtk-3-dev
sudo apt-get install libgtk2.0-dev

thanks @arturo, it seems to do the trick to unistall libgtk3-dev.

just a question, if i need to have both gtk2 and gtk3 installed, is there way to force the use of gtk2?

i saw there was a GTK_MAJOR_VERSION defined in ofSystemUtils, but i don’t see where it’s get the value.

should i close the issue on github?

Same issue for me with of 0.9.3 and opencv
I had to remove gtk3-dev as mentionned by arturo
and also, when using qtcreator, to modify libs/openFrameworksCompiled/project/qtcreator/modules/of/of.qbs and change gtk±3.0 with gtk±2.0 in pkg-config modules