gtkmm的CMake错误 [英] CMake error with gtkmm

查看:109
本文介绍了gtkmm的CMake错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Debian 8,并安装了libgtkmm-3.0(以及-dev).现在,我有一个使用gtkmm的非常简单的程序,基本上是一个Hello World:

I'm using Debian 8 and have installed libgtkmm-3.0 (and also -dev). Now I have a very simple program using gtkmm, basically a Hello World:

main.cpp:

#include "../include/BrowserWindow.class.hpp"
#include <gtkmm/application.h>

int main(int argv, char *argc[])
{
    Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

    BrowserWindow helloworld;

    //Shows the window and returns when it is closed.
    return app->run(helloworld);
}

BrowserWindow.class.cpp:

BrowserWindow.class.cpp:

#include "../include/BrowserWindow.class.hpp"
#include <iostream>

BrowserWindow::BrowserWindow()
: m_button("Hello World")  
{
  set_border_width(10);

  m_button.signal_clicked().connect(sigc::mem_fun(*this, &BrowserWindow::on_button_clicked));

  add(m_button);

  m_button.show();
}

BrowserWindow::~BrowserWindow()
{
}

void BrowserWindow::on_button_clicked()
{
  std::cout << "Hello World" << std::endl;
}

BrowserWindow.class.hpp:

BrowserWindow.class.hpp:

#ifndef VB_BROWSERWINDOW_CLASS_H
#define VB_BROWSERWINDOW_CLASS_H

#include <gtkmm/button.h>
#include <gtkmm/window.h>

class BrowserWindow : public Gtk::Window
{

public:
  BrowserWindow();
  virtual ~BrowserWindow();

protected:
  void on_button_clicked();

  Gtk::Button m_button;
};
#endif

现在,如果我使用pkg-config gtkmm-3.0 --cflags和pkg-config gtkmm-3.0 --libs手动或使用自制的makefile进行编译,则一切正常.但是,使用CMake会出现编译错误.运行cmake很好:

Now, if I compile it manually or with a selfmade makefile, using pkg-config gtkmm-3.0 --cflags and pkg-config gtkmm-3.0 --libs, everything works fine. However, with CMake I get compiling errors. Running cmake is fine:

-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28") 
-- checking for module 'gtkmm-3.0'
--   found gtkmm-3.0, version 3.14.0
-- Configuring done
-- Generating done
-- Build files have been written to: bla/bla/build

现在运行make是个问题:

Running make is the problem now:

projectdir/hardsource/main.cpp: In function ‘int main(int, char**)’:
projectdir/hardsource/main.cpp:6:102: error: no matching function for call to ‘Gtk::Application::create(char**&, int&, const char [18])’
         Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

之后是一些我可能想要的功能的潜在候选对象" ...

followed by some potential "candidates" of functions I could have meant...

CMakeLists.txt:

The CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(myproject)

find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)

link_directories(${GTKMM_LIBRARY_DIRS})
include_directories(include ${GTKMM_INCLUDE_DIRS})

file(GLOB SOURCES "hardsource/*.cpp")

add_executable(mybinary ${SOURCES})

target_link_libraries(mybinary ${GTKMM_LIBRARIES})

我比较了手动pkg-config生成的编译器标志(包括lib)和cmake的pkg-config生成的标志.两者完全相同.

I compared compiler flags (include as well as lib) generated with manual pkg-config and the one generated by cmake's pkg-config. Both are identically.

那么,怎么了?:/

推荐答案

您已在主函数中交换了 argc argv .更改:

You have swapped around argc and argv in your main function. Change:

int main(int argv, char *argc[])

进入

int main(int argc, char *argv[])

请参见 int argc,char * argv []是什么意思?

作为旁注,我怀疑它是否真的可以使用自制的Makefile.也许您并没有真正编译所有文件.

As a side note, I doubt it was really working with a self-made Makefile. Maybe you were not really compiling all files.

这篇关于gtkmm的CMake错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆