我在Ubuntu 13.10使用gtkmm的3.0 dev軟件包,編譯以下代碼:gtkmm的-3.0編譯代碼投擲GTK + 2的符號錯誤
#include <gtkmm.h>
#include <iostream>
#include "opencv2/opencv.hpp"
#include <chrono>
#include <thread>
#include <mutex>
//GASP! global vars!
std::mutex FRAME_MUTEX;
std::thread CV_THREAD;
cv::Mat FRAME, CLEAN;
Glib::Dispatcher dispatcher;
volatile bool THREADRUN;
void cvThread() {
THREADRUN = true;
cv::VideoCapture capture(0);
while(THREADRUN) {
FRAME_MUTEX.lock();
capture >> FRAME;
FRAME_MUTEX.unlock();
dispatcher.emit();
}
}
int main(int argc, char** argv)
{
Gtk::Main gtkMain(argc, argv);
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("main_window.glade");
Gtk::Window *mainWindow;
Gtk::Image *cleanDisplay;
Gtk::Image *evmDisplay;
builder->get_widget("main_window", mainWindow);
builder->get_widget("clean_display", cleanDisplay);
builder->get_widget("evm_display", evmDisplay);
dispatcher.connect([&]() {
FRAME_MUTEX.lock();
cv::cvtColor(FRAME, CLEAN, CV_BGR2RGB);
cleanDisplay->set(Gdk::Pixbuf::create_from_data(CLEAN.data, Gdk::COLORSPACE_RGB, false, 8, CLEAN.cols, CLEAN.rows, CLEAN.step));
cleanDisplay->queue_draw();
FRAME_MUTEX.unlock();
});
CV_THREAD = std::thread(&cvThread);
gtkMain.run(*mainWindow);
return 0;
}
使用命令:
$ g++ test.cpp -o uitest `pkg-config --cflags --libs gtkmm-3.0 opencv` -std=c++11
編譯工作正常,但是當我運行可執行文件時,它失敗並出現以下錯誤:
(uitest:20300): Gtk-ERROR **: GTK+ 2.x symbols detected.
Using GTK+ 2.x and GTK+ 3 in the same process is not supported
Trace/breakpoint trap (core dumped)
這是我第一次嘗試pt深入研究使用gtkmm,並且我不知道要去哪裏開始調試。我檢查了glade文件,它頂部有一個xml註釋,表示該文件的內容需要gtk + 3。答案here對我沒有多大幫助;我從以下指令得到以下輸出:
-lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4
-lcairomm-1.0 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0
-lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann
-lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml
-lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres
-lopencv_ts -lopencv_video -lopencv_videostab
有關如何解決此問題的任何建議?