Jump to content

Anyone has any experiences with Glib?

wasab
Go to solution Solved by wasab,

https://askubuntu.com/questions/703611/how-to-call-desktop-notifications-on-ubuntu-gnome

 

I found an alternative. Looks like I do not need to do this programmatically. I can just run a shell command.

Long story short, I am trying to make a gnome notification service. I plan to daemonize it and have it push notifications to the gnome notification tray whenever chat server(which i am also gonna make one from scratch) send out a message. It will be more or less a notification service that runs in the background and pushes messages to the gnome notification tray. 

 

For this, I am using the gnome Glib library, Clion, and developing on fedora 30. 

My major issue is that the compiler keep on throwing me linkage error. It doesnt seem to be able to find the dependency it needs(Glib). I tried both cmake and using the gcc terminal commands, no luck. Can anyone help me out? 

 

My main.c (this is a test code) 

#include <stdio.h>
#include <gio/gio.h>
int main() {
    GApplication* application = g_application_new ("Test", G_APPLICATION_FLAGS_NONE);
    GNotification* notification = g_notification_new("Test Title");
    g_notification_set_body(notification, "Test body");
    g_notification_set_priority(notification, G_NOTIFICATION_PRIORITY_NORMAL);
    g_application_send_notification(application, "Test Id", notification);
    return 0;
}

 

My cmake file 

cmake_minimum_required(VERSION 3.14)
project(gnome_notification C)

set(CMAKE_C_STANDARD 99)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
include_directories(${GLIB_INCLUDE_DIRS})



set(SOURCE_FILES main.c)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${GLIB_LIBRARIES})

 

 

What the error looks like. As you can see, undefined referenced.

 

1652300091_Screenshotfrom2019-06-0614-12-24.png.4ba27992bd47c0cb5583ec51abb66644.png

 

 

It is confirmed I already have glib installed. 

2041969792_Screenshotfrom2019-06-0614-17-27.png.5b092ebd4db48c246934a68a01ea107e.png

 

 

Can someone help me out? 

 

I follow the guide on here. 

https://wiki.gnome.org/HowDoI/GNotification

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

I think your problem is that you're depending on glib rather than gio. It compiles and links correctly for me (on Fedora 29) with

gcc main.c `pkg-config --libs --cflags gio-2.0`

I've not used any of these libraries before, I was just curious and looked into it enough to get this to work, so I won't necessarily be able to help with any other issues.

The program doesn't actually run at the moment though, because the application ID needs to match a certain format and the application then needs to be registered.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, colonel_mortis said:

I think your problem is that you're depending on glib rather than gio. It compiles and links correctly for me (on Fedora 29) with


gcc main.c `pkg-config --libs --cflags gio-2.0`

I've not used any of these libraries before, I was just curious and looked into it enough to get this to work, so I won't necessarily be able to help with any other issues.

The program doesn't actually run at the moment though, because the application ID needs to match a certain format and the application then needs to be registered.

I see. I will try it out. I thought gio is part of the glib. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

@colonel_mortis

 

No luck. pkgconfig cant even finds the package this time around. I really do not understand why including a library in C is so difficult. :( 

 

 

1889583438_Screenshotfrom2019-06-0619-14-30.png.4bcd56cb0e2f6b1d4baf20c3feec477f.png

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, wasab said:

@colonel_mortis

 

No luck. pkgconfig cant even finds the package this time around. I really do not understand why including a library in C is so difficult. :( 

 

 

1889583438_Screenshotfrom2019-06-0619-14-30.png.4bcd56cb0e2f6b1d4baf20c3feec477f.png

The argument to pkg-config should be gio-2.0 not glib-2.0, or at least using gio was what made it compile correctly for me.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, colonel_mortis said:

The argument to pkg-config should be gio-2.0 not glib-2.0, or at least using gio was what made it compile correctly for me.

I tried both glib and gio :(

 

734816320_Screenshotfrom2019-06-0619-21-12.png.2c850fe41e3f3cc15cbfcc8cffeee3ab.png

 

What packages did you install on Fedora to have gio? I got gio.h in my usr/include/ by installing the glib2-devel package. Maybe I installed the wrong package. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

gcc main.c -o main `pkg-config --libs --cflags gio-2.0`

I've got an identical setup and worked for me. I don't recall installing any specific library in the past. Could be bundled with glib. Since you got the headers and you still get pkg-config errors, try finding the gio-2.0.pc or similar. It should be in /usr/lib(64)/pkgconfig/. If it's there, you might want to check what pkg-config search paths are. Maybe something is misconfigured somehow.

Link to comment
Share on other sites

Link to post
Share on other sites

 
 
1
Just now, DevBlox said:

gcc main.c -o main `pkg-config --libs --cflags gio-2.0`

I've got an identical setup and worked for me. I don't recall installing any specific library in the past. Could be bundled with glib. Since you got the headers and you still get pkg-config errors, try finding the gio-2.0.pc or similar. It should be in /usr/lib(64)/pkgconfig/. If it's there, you might want to check what pkg-config search paths are. Maybe something is misconfigured somehow.

yes, i found gio-2.0.pc inside /usr/lib64/pkgconfig/

 

PKG_CONFIG_PATH variable is empty when I initially printed it out. Something is indeed terribly misconfigured. I exported the correct directory to the environment variable, it throws me the same error nevertheless. Not sure why. I think i will just use shell command for the notification or use python and the notify2 module.  

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×