CMake error with gtkmm

不打扰是莪最后的温柔 提交于 2021-02-07 20:32:29

问题


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:

#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:

#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

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

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...

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})

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.

So, what's wrong? :/


回答1:


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

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

into

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

See What does int argc, char *argv[] mean?

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



来源:https://stackoverflow.com/questions/37301250/cmake-error-with-gtkmm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!