[SOLVED] Utilising libgcal-0.9.6 to work with Google Calendars

  • I'm having a problem adding a library to work with and compile into my program.

    I'm working on Linux Mint 17 64bit and I am using:
    Qt Creator 3.1.2 (opensource)
    Qt 5.3.1 (GCC 4.6.1 64 bit)

    I am wanting my program to be able write an appointment made in a calendar widget that I have written, as a child class of QCalendarWidget to the/my Google Calendar. The appointment is also stored in a local database.

    I have downloaded and build libgcal-0.9.6, following the instructions; dealing with the dependences and in seems to have installed correctly.

    Initially I included my own LIBS and INCLUDEPATH statements in the profile, but when that didn't work I tried the right-click and Add library... option in Qt Creator, which just results in the same error. My additions occour first and the generated ones appear second with all the extra parent folder steps.

    I have included the majority of my profile, excluding all the Source and Header file inclusions; below and the source code which generates the errors, which is virtually the example code provided, but with a couple of modifications to make it work within my program. The errors relate to the compilation or rather the linking rather than problems in the code.

    The Profile:
    @QT += core gui
    QT += sql
    QT += network
    QT += xml
    QT += printsupport

    CONFIG += qt warn_on
    CONFIG += c++11

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    unix {
    INCLUDEPATH += "/home/mike/hunspell-1.3.3/src/hunspell"
    LIBS += /usr/local/lib/libhunspell-1.3.so

    INCLUDEPATH += "/usr/local/include/libgcal"
    LIBS += "/usr/local/lib/libgcal.so"


    win32 {
    INCLUDEPATH += C:/path/to/hunspell/include
    LIBS += C:/path/to/hunspell/Release/hunspell.lib

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/release/ -lgcal
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/debug/ -lgcal
    else:unix: LIBS += -L$$PWD/../../../../../usr/local/lib/ -lgcal
    INCLUDEPATH += $$PWD/../../../../../usr/local/include/libgcal
    DEPENDPATH += $$PWD/../../../../../usr/local/include/libgcal@

    The Source code:
    @bool Appointment_Editor_Dialog::add_GoogleCal()
    bool retval(false);
    char name[28] = "johnsmith@googlemail.com";
    char pass[14] = "***********";

    gcal_t gcal;
    gcal_event_t event;
    int result;
    /* Create a gcal 'object' and authenticate with server */
    if (!(gcal = gcal_new(GCALENDAR)))

    // if (argc == 3)
    // result = gcal_get_authentication(gcal, argv[1], argv[2]);
    // else
    result = gcal_get_authentication(gcal, name, pass );

    /* Create an event 'object' and fill in some data */
    if ((event = gcal_event_new(NULL))) {
            gcal_event_set_title(event, ui->lineEdit_Title->text().toUtf8());
            gcal_event_set_content(event, "Here goes the description");
              QString temp_start(ui->dateEdit_Start->date().toString("yyyy-MM-dd"));
            temp_start += "T";
            temp_start += ui->timeEdit_Start->time().toString("HH:mm");
            temp_start += ":00Z";
            QString temp_end(ui->dateEdit_End->date().toString("yyyy-MM-dd") + "T" + ui->timeEdit_End->time().toString("HH:mm") + ":00Z");
            gcal_event_set_start(event, temp_start.toStdString().c_str());
            gcal_event_set_end(event, temp_end.toStdString().c_str());
            gcal_event_set_where(event, "A nice place for a meeting");
    /* Add a new event */
    if (!(result = gcal_add_event(gcal, event))) {
            /* Edit this event */
            gcal_event_set_title(event, "Changing the title");
            result = gcal_update_event(gcal, event);
            /* Delete this event (note: google doesn't really deletes
             * the event, but set its status to 'cancelled' and keeps
             * then for nearly 4 weeks).
            result = gcal_erase_event(gcal, event);
    /* Cleanup */


    This code was to prove it worked, I'll worry about the quality of the code once I have the library working (though feel free to make suggestions); I wasn't intending to hard code the email address and pass word in to the code.

    Samples of the errors are a list below (though one occours for every library function called:
    @undefined reference to 'gcal_new(gservice)'
    undefined reference to 'gcal_get_authentication(gcal_resource*, char*, char*)'
    undefined reference to `gcal_event_new(char*)'@

    The two declarations at the start don't generate any errors:
    gcal_t gcal;
    gcal_event_t event;

    These occur for every function within the library used within the method.

    GCC seems to be finding the Header file and the Library, but not the functions within them, if I change the path to make it not find them the errors I get are different, which suggests it is finding the files.

    As I was writing this it occurs to me that the version of gcc used elsewhere on my system is 4.8.2, if that is the problem, how do I get the library compiled by the right version? I recently added hunspell, following a similar process and didn't have these problems.

    Any suggestions welcome.

  • Is libgcal a C-library ?
    If so do the header files have extern "C" around their function declarations?
    If not then you may need to put extern "C" around includes.

  • libcal is a c library, so adding the following around the header made it work

    @extern "C" {
    #include <gcalendar.h>

    Thank you very much for your help, it's appreciated.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.