为 gtk、gtkmm 和 opencv 更正 CMakeLists.txt 文件
Posted
技术标签:
【中文标题】为 gtk、gtkmm 和 opencv 更正 CMakeLists.txt 文件【英文标题】:Correct CMakeLists.txt file for gtk, gtkmm and opencv 【发布时间】:2016-03-08 23:00:13 【问题描述】:我正在尝试编译一个使用 gtkmm 和 opencv 的 GTK2 程序。我用命令行 g++ 试过了:
g++ main.cpp -o bla `pkg-config --cflags --libs gtkmm-2.4 opencv`
这会引发与下面的输出相同的错误。
我用 cmake 和下面的 CMakeLists.txt 文件尝试过:
project (gtk-test)
cmake_minimum_required (VERSION 2.4)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTK2 REQUIRED gtk+-2.0)
include_directories ($GTK2_INCLUDE_DIRS)
link_directories ($GTK2_LIBRARY_DIRS)
add_executable (gtk-test main.c)
add_definitions ($GTK2_CFLAGS_OTHER)
target_link_libraries (gtk-test $GTK2_LIBRARIES)
cmake 。 && 制作:
CMake Warning (dev) at CMakeLists.txt:6 (link_directories):
This command specifies the relative path
$GTKMM_LIBRARY_DIRS
as a link directory.
Policy CMP0015 is not set: link_directories() treats paths relative to the
source dir. Run "cmake --help-policy CMP0015" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/alefveld/Downloads/gtkcv
[ 25%] Building CXX object CMakeFiles/bla.dir/MainWindow.cpp.o
In file included from /Users/alefveld/Downloads/gtkcv/MainWindow.cpp:1:
In file included from /Users/alefveld/Downloads/gtkcv/MainWindow.hpp:12:
In file included from /usr/local/include/gtkmm-2.4/gtkmm/window.h:7:
In file included from /usr/local/include/glibmm-2.4/glibmm.h:87:
In file included from /usr/local/include/glibmm-2.4/glibmm/thread.h:49:
In file included from /usr/local/include/glibmm-2.4/glibmm/error.h:23:
In file included from /usr/local/include/glibmm-2.4/glibmm/exception.h:25:
/usr/local/include/glibmm-2.4/glibmm/ustring.h:267:13: error: expected ';' at
end of declaration list
~ustring() noexcept;
^
;
/usr/local/include/glibmm-2.4/glibmm/ustring.h:881:48: warning: deleted function
definitions are a C++11 extension [-Wc++11-extensions]
FormatStream(const ustring::FormatStream&) = delete;
^
/usr/local/include/glibmm-2.4/glibmm/ustring.h:882:59: warning: deleted function
definitions are a C++11 extension [-Wc++11-extensions]
FormatStream& operator=(const ustring::FormatStream&) = delete;
^
/usr/local/include/glibmm-2.4/glibmm/ustring.h:894:18: error: expected ';' at
end of declaration list
~FormatStream() noexcept;
^
;
/usr/local/include/glibmm-2.4/glibmm/ustring.h:1273:45: warning: deleted
等等。我在这里想念什么?任何帮助将不胜感激。如何一次性编译 Gtk/gtkmm 和 opencv?
【问题讨论】:
你尝试谷歌错误信息吗? Here 他们说你需要启用 C++11。 我用谷歌搜索了很多次:-) 但是我没有用谷歌搜索 C++11 错误。这似乎很有帮助,谢谢,我会试试看。 【参考方案1】:GTKmm 和 GTK 是两个不同的东西。 GTKmm 是 GTK 的 C++ 绑定,因此 GTKmm 依赖于 GTK 库。
对于 CMake 和 GTKmm,只需查看using CMake with GTKmm 上的官方 wiki 页面。
【讨论】:
以上是关于为 gtk、gtkmm 和 opencv 更正 CMakeLists.txt 文件的主要内容,如果未能解决你的问题,请参考以下文章
将 C 中的 gtk3 与 C++ 中的 gtkmm 结合起来
GTKmm - 无法将固定大小设置为 Gtk::Scale 小部件
从opencv读取时gtkmm DrawingArea分段错误