Hi
I've tried to use pgkconfig to compile my project.
I used this as an example:
http://www.vtk.org/Wiki/CMake:How_To_Find_Libraries
chapter 4.1
I get the following Errormessage:
fatal error: /gtk/gtk.h: Datei oder Verzeichnis nicht gefunden
German: Datei oder Verzeichnis nicht gefunden
English: File or directory not found
Please help me
Regard
David
cmake_minimum_required (VERSION 2.6)
project (GUI)
# - Try to find ImageMagick++
# Once done, this will define
#
# Magick++_FOUND - system has Magick++
# Magick++_INCLUDE_DIRS - the Magick++ include directories
# Magick++_LIBRARIES - link these to use Magick++
include(LibFindMacros.cmake)
set(GTK+-3.0_INCLUDE_DIR /gtk-3.0/)
add_executable(TEST test.c)
# Dependencies
libfind_package(/pkgconfig/GTK+-3.0 GTK)
# Use pkg-config to get hints about paths
libfind_pkg_check_modules(GTK+-3.0_PKGCONF gtk+-3.0)
# Include dir
find_path(GTK+-3.0_INCLUDE_DIR
NAMES gtk.h
PATHS ${GTK+-3.0_PKGCONF_INCLUDE_DIRS}
)
MESSAGE("path" ${GTK+-3.0_PKGCONF_INCLUDE_DIRS})
include_directories(${GTK+-3.0_INCLUDE_DIR})
# Finally the library itself
find_library(GTK+-3.0_LIBRARY
NAMES GTK+-3.0
PATHS ${GTK+-3.0_PKGCONF_LIBRARY_DIRS}
)
target_link_libraries(TEST GTK+-3.0_LIBRARY)
# Set the include dir variables and the libraries and let libfind_process do
the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib
depends on.
set(GTK+-3.0_PROCESS_INCLUDES GTK+-3.0_INCLUDE_DIR GTK_INCLUDE_DIRS)
set(GTK+-3.0_PROCESS_LIBS GTK+-3.0_LIBRARY GTK_LIBRARIES)
libfind_process(GTK+-3.0)
# add the install targets
install (TARGETS TEST DESTINATION ${PROJECT_BINARY_DIR})
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
# used for the current package. For this to work, the first parameter must be the
# prefix of the current package, then the prefix of the new package etc, which are
# passed to find_package.
macro (libfind_package PREFIX)
set (LIBFIND_PACKAGE_ARGS ${ARGN})
if (${PREFIX}_FIND_QUIETLY)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
endif (${PREFIX}_FIND_QUIETLY)
if (${PREFIX}_FIND_REQUIRED)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
endif (${PREFIX}_FIND_REQUIRED)
find_package(${LIBFIND_PACKAGE_ARGS})
endmacro (libfind_package)
# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
# where they added pkg_check_modules. Consequently I need to support both in my scripts
# to avoid those deprecated warnings. Here's a helper that does just that.
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
macro (libfind_pkg_check_modules PREFIX PKGNAME)
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(${PREFIX} ${PKGNAME})
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
endmacro (libfind_pkg_check_modules)
# Do the final processing once the paths have been detected.
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
# all the variables, each of which contain one include directory.
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
# Also handles errors in case library detection was required, etc.
macro (libfind_process PREFIX)
# Skip processing if already processed during this run
if (NOT ${PREFIX}_FOUND)
# Start with the assumption that the library was found
set (${PREFIX}_FOUND TRUE)
# Process all includes and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
if (${i})
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)
# Process all libraries and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_LIBS})
if (${i})
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)
# Print message and/or exit on fatal error
if (${PREFIX}_FOUND)
if (NOT ${PREFIX}_FIND_QUIETLY)
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
endif (NOT ${PREFIX}_FIND_QUIETLY)
else (${PREFIX}_FOUND)
if (${PREFIX}_FIND_REQUIRED)
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
message("${i}=${${i}}")
endforeach (i)
message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
endif (${PREFIX}_FIND_REQUIRED)
endif (${PREFIX}_FOUND)
endif (NOT ${PREFIX}_FOUND)
endmacro (libfind_process)
macro(libfind_library PREFIX basename)
set(TMP "")
if(MSVC80)
set(TMP -vc80)
endif(MSVC80)
if(MSVC90)
set(TMP -vc90)
endif(MSVC90)
set(${PREFIX}_LIBNAMES ${basename}${TMP})
if(${ARGC} GREATER 2)
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
endif(${ARGC} GREATER 2)
find_library(${PREFIX}_LIBRARY
NAMES ${${PREFIX}_LIBNAMES}
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
)
endmacro(libfind_library)
#include </gtk/gtk.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
GtkWidget *window;
GtkWidget *grid;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *quitButton;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *dialog;
int x = 0;
// Habe diese Variable hierher kopiert aufgrund von Fehlermeldung:
// warning: function returns address of local variable
char combined[200];
FILE *file;
//Create a filename. Function creates String: pw(X-Value).txt
char* createFilename(int x){
char buffer [33];
char first[100];
char last[100];
char middle[100];
strcpy(first, "pw");
sprintf(buffer, "%s%d", "", x);
strcpy(middle,buffer);
strcpy(last, ".txt");
strcpy(combined, first);
strcat(combined, middle);
strcat(combined, last);
return combined;
}
bool checkFileExists(char* filename){
if(fopen(filename, "r")==NULL){
return false;
}
return true;
}
void writeToFile(){
char* filename=malloc(50);
/* Check if file exist and try filename: pw(+1).txt if the file exists
*/
strcpy(filename,createFilename(x));
while(checkFileExists(filename)){
x++;
strcpy(filename,createFilename(x));
}
printf("fn:%s",filename);
file = fopen(filename,"w");
fprintf(file,"%s",gtk_entry_get_text(GTK_ENTRY(entry1))); /*writes content of entry1*/
fprintf(file,"%s","\n"); /*writes*/
fprintf(file,"%s",gtk_entry_get_text(GTK_ENTRY(entry2))); /*writes content of entry2*/
fclose(file); /*done!*/
free(filename);
}
static void
save_file (GtkWidget *widget,
gpointer data)
{
//Check if user has entered a password
if (strlen(gtk_entry_get_text(GTK_ENTRY(entry1)))==0 || strlen(gtk_entry_get_text(GTK_ENTRY(entry2)))==0){
printf("error");
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s","Please enter PC and userpassword");
/*
*/
}
else{
writeToFile();
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"Passwords are strored in File pw%i.txt",x);
}
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_print ("Save file\n");
}
static void
reset_text (GtkWidget *widget,
gpointer data)
{
gtk_entry_set_text(GTK_ENTRY(entry1),"");
gtk_entry_set_text(GTK_ENTRY(entry2),"");
g_print ("Reset text\n");
}
int
main (int argc,
char *argv[])
{
/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application.
*/
gtk_init (&argc, &argv);
/* create a new window, and set its title */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Passworteditor");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Here we construct the container that is going pack our buttons */
grid = gtk_grid_new ();
/* Pack the container in the window */
gtk_container_add (GTK_CONTAINER (window), grid);
button1 = gtk_button_new_with_label ("Save");
g_signal_connect (button1, "clicked", G_CALLBACK (save_file), NULL);
/* Place the first button in the grid cell (0, 0), and make it fill
* just 1 cell horizontally and vertically (ie no spanning)
*/
gtk_grid_attach (GTK_GRID (grid), button1, 3, 0, 1, 1);
button2 = gtk_button_new_with_label ("Reset");
g_signal_connect (button2, "clicked", G_CALLBACK (reset_text), NULL);
/* Place the second button in the grid cell (1, 0), and make it fill
* just 1 cell horizontally and vertically (ie no spanning)
*/
gtk_grid_attach (GTK_GRID (grid), button2, 3, 1, 1, 1);
quitButton = gtk_button_new_with_label ("Quit");
g_signal_connect (quitButton, "clicked", G_CALLBACK (gtk_main_quit), NULL);
/* Place the Quit button in the grid cell (0, 1), and make it
* span 2 columns.
*/
gtk_grid_attach (GTK_GRID (grid), quitButton, 4, 0, 2, 2);
/* Now that we are done packing our widgets, we show them all
* in one go, by calling gtk_widget_show_all() on the window.
* This call recursively calls gtk_widget_show() on all widgets
* that are contained in the window, directly or indirectly.
*/
//Set window position
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
//Set if window is resizable
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
label1 = gtk_label_new("PC:");
label2 = gtk_label_new("User:");
gtk_grid_attach (GTK_GRID (grid), label1, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), label2, 1, 1, 1, 1);
entry1 = gtk_entry_new();
gtk_grid_attach (GTK_GRID (grid), entry1, 2, 0, 1, 1);
entry2 = gtk_entry_new();
gtk_grid_attach (GTK_GRID (grid), entry2, 2, 1, 1, 1);
gtk_widget_show_all (window);
/* All GTK applications must have a gtk_main(). Control ends here
* and waits for an event to occur (like a key press or a mouse event),
* until gtk_main_quit() is called.
*/
gtk_main ();
return 0;
}
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake