我如何在Neatbeans上编译HAL示例



我正试图在Netbeans上编译HAL API示例。Netbeans显示有关某些头文件的警告和错误。但是我能够使用以下命令行编译示例代码:

gcc `pkg-config --libs --cflags dbus-1 hal hal-storage dbus-glib-1 glib-2.0` main.c HalDemos.c HalDemos.h -o HalDemos -lpthread

如何将此命令应用到我的Netbeans项目?

下面是我要编译的代码:

/* 
 * File:   HallDemos.h
 * Author: olcay
 *
 * Created on December 25, 2011, 5:05 AM
 */
#ifndef HALLDEMOS_H
#define HALLDEMOS_H
#ifdef  __cplusplus
extern "C" {
#endif
#include <hal/libhal.h>
#include <hal/libhal-storage.h>
#include <dbus/dbus.h>
#include <glib-1.2/glib.h>
//#include <dbus/dbus-glib-lowlevel.h>
    #define HAL_DBUS_SERVICE "org.freedesktop.Hal"
    #define HAL_ROOT_COMPUTER "/org/freedesktop/Hal/devices/computer"
    #define HAL_DBUS_INTERFACE_POWER "org.freedesktop.Hal.Device.SystemPowerManagement"
    static void handle_device_removed(LibHalContext *ctx, const char *udi);
    static void handle_device_added(LibHalContext *ctx, const char *udi);
    DBusConnection *connection;
    DBusError error;
    DBusMessage *mess;
    DBusMessage *reply;
    LibHalContext *ctx;
    LibHalDrive *drive;
    LibHalVolume *volume;
    const char *udi;
    int exit_code;
    int initHal();
    int getSystemInfo();
    int getDeviceWithCapability(const char *capability);
    void callbackLoop();
    void listDeviceContent();

#ifdef  __cplusplus
}
#endif
#endif  /* HALLDEMOS_H */


#include "HalDemos.h"
#include <stdio.h>
static void handle_device_removed(LibHalContext *ctx, const char *udi) {
    printf("Device with udi=%s is removedn", udi);
}
static void handle_device_added(LibHalContext *ctx, const char *udi) {
    dbus_bool_t is_storage;
    is_storage = libhal_device_query_capability(ctx, udi, "storage", NULL);
    if (is_storage) {
        drive = libhal_drive_from_udi(ctx, udi);
        volume = libhal_volume_from_udi(ctx, udi);
        if (libhal_drive_is_hotpluggable(drive) || libhal_drive_uses_removable_media(drive)) {
            printf("Storage device added %s model %sn",
                    libhal_drive_get_device_file(drive),
                    libhal_drive_get_model(drive));
            //printf("Mount point = %sn", libhal_volume_get_mount_point(volume));
        }
        libhal_drive_free(drive);
    }
    //printf("Device with udi=%s is addedn", udi);
}
int initHal() {
    udi = "/org/freedesktop/Hal/devices/computer";
    dbus_error_init(&error);
    connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
    if (dbus_error_is_set(&error)) {
        printf("Unable to connect to Dbus: %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    ctx = libhal_ctx_new();
    if (!libhal_ctx_set_dbus_connection(ctx, connection)) {
        printf("Error: %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    if (!libhal_ctx_init(ctx, &error)) {
        printf("Hal context initializing failure %sn", error.message);
        return 1;
    }
}
int getSystemInfo() {
    char *kernel_version = libhal_device_get_property_string(ctx, udi, "system.kernel.version", &error);
    if (dbus_error_is_set(&error)) {
        printf("Error getting string property %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    char *power_management_type = libhal_device_get_property_string(ctx, udi, "power_management.type", &error);
    if (dbus_error_is_set(&error)) {
        printf("Error getting string property %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    dbus_bool_t can_hibernate = libhal_device_get_property_bool(ctx, udi, "power_management.can_hibernate", &error);
    if (dbus_error_is_set(&error)) {
        printf("Error getting bool property %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    printf("System information:n");
    printf("Kernel                = %sn", kernel_version);
    printf("Power management type = %sn", power_management_type);
    printf("Hibernate             = %sn", can_hibernate ? "Supported" : "Not supported");
    libhal_free_string(kernel_version);
    libhal_free_string(power_management_type);
    return 0;
}
int getDeviceWithCapability(const char* capability) {
    int num_devices = 0;
    char **udis = libhal_find_device_by_capability(ctx, capability, &num_devices, &error);
    if (dbus_error_is_set(&error)) {
        printf("Error getting bool property %sn", error.message);
        dbus_error_free(&error);
        return 1;
    }
    if (num_devices == 0) {
        printf("No device found with input capability!");
        return 0;
    }
    int i;
    printf("Devices with input capability:n");
    for (i = 0; udis[i]; i++) {
        printf("%2d - udi = %sn", i + 1, udis[i]);
        /* Do something with it */
    }
    /* Free the string array */
    libhal_free_string_array(udis);
}
void callbackLoop() {
    GMainLoop *loop;
    loop = (GMainLoop*) g_main_loop_new(NULL, FALSE);
    dbus_connection_setup_with_g_main(connection, NULL);
    libhal_ctx_set_device_added(ctx, handle_device_added);
    libhal_ctx_set_device_removed(ctx, handle_device_removed);
    g_main_loop_run(loop);
}
void listDeviceContent(){
}

更新:

编写我在$$()中使用的命令并将其添加到其他编译器设置中解决了我的问题。

进入你的项目属性-> Build -> C Compiler -> Additional Options
将编译器标志放在$$()之间,如:

$$(pkg-config --libs --cflags dbus-1 hal hal-storage dbus-glib-1 glib-2.0)

相关内容

  • 没有找到相关文章

最新更新