Vala not compiling GMenu

I am trying to get a hang of vala. It is an interesting project and I am trying to build an app for Budgie.

Unfortunately, the documentation seems not too complete.

I am trying to build this simple app from here , but every time I try to compile using meson, I always get the error message:

The symbol `GMenu' could not be found

I figure this is due to a missing library, and tried installing libgnome-menu-3-dev, but it’s already and installed and didn’t solve the issue.

Any hint?

you mentioned you are using meson - what is your meson.build file?

That’s the file:

project('com.github.rainer' , 'vala' , 'c')

    executable (
    meson.project_name(),
    'Window.vala',
   'Application.vala',
       dependencies: [
             dependency('gtk+-3.0')
       ],
   install: true
 )

the example gave the direct compilation as:

valac --pkg gio-unix-2.0 --pkg libgnome-menu -o gnomemenusample GnomeMenuSample.vala -X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE"

So you’ll need to add each of the --pkg entries as part of the meson file - I’m not sure dependencies is the correct thing - worth a try I suppose - guessing should be vala_args:

project('com.github.rainer' , 'vala' , 'c')

    executable (
    meson.project_name(),
    'Window.vala',
   'Application.vala',
       vala_args: [
             '--pkg', 'gtk+-3.0',
             '--pkg', 'libgnome-menu-3.0',
             '--pkg', 'gio-unix-2.0',       
      ],
   install: true
 )

This bit will need to be added to meson: “-DGMENU_I_KNOW_THIS_IS_UNSTABLE” which is a c_arg

i.e.

project('com.github.rainer' , 'vala' , 'c')

    executable (
    meson.project_name(),
    'Window.vala',
   'Application.vala',
       vala_args: [
             '--pkg', 'gtk+-3.0',
             '--pkg', 'libgnome-menu-3.0',
             '--pkg', 'gio-unix-2.0',       
      ],
      c_args: [
        '-DGMENU_I_KNOW_THIS_IS_UNSTABLE',
      ],
   install: true
 )

… doing all this from memory … so probably needs a bit of fiddling to get the syntax etc right.

One step closer; there is still one small issue, though:

../GnomeMenuSample.vala:9.18-9.31: error: The type name `GMenu.TreeItem' could not be found
    foreach (GMenu.TreeItem item in root.get_contents ()) {

Compiling with the command indicated in the tutorial :

valac --pkg gio-unix-2.0 --pkg libgnome-menu -o gnomemenusample GnomeMenuSample.vala -X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE"

throws the following error:

fatal error: gnome-menus/gmenu-tree.h: No such file or directory  #include <gnome-menus/gmenu-tree.h>

hmm … looks like that is an out of date example

get_root_directory() returns a TreeDirectory

Think now you have to use “get_tree” on that return value which returns a Tree … etc

There doesn’t appear to be a TreeItem any more

This is how budgie menu’s work https://github.com/solus-project/budgie-desktop/blob/master/src/applets/budgie-menu/BudgieMenuWindow.vala#L117

Thanks for looking into this, David. I see what I can do from here. I on the Slingswarm application. But your advice was very helpful.

I am starting to get used to Vala and like it.

Working my way through Vala. I am still trying to get the Slingshot App to work, but ran into another compiling issue that I can’t figure out.

The are zillions of answers on the net for Java, but only few threads for Vala.

When I try to compile, I get the error message:

/usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: 
DSO missing from command line collect2: 
error: ld returned 1 exit status

I found an answer on StackOverFlow, that recommends to install the missing library. Searching on Ubuntu Packages, the closest package in name I found, was

libm17n-dev

what I installed and added to the meson build file, what now looks like this:

executable(
    meson.project_name(),
    './SlingshotWindow.vala',
    './Frontend/Widgets/Utilities.vala',
    './Frontend/Widgets/Color.vala',
    './Backend/GMenuEntries.vala',
    './Frontend/Widgets/CompositedWindow.vala',
    './Frontend/Widgets/Searchbar.vala',
    './Frontend/Widgets/AppItem.vala',
    './Frontend/Widgets/Indicators.vala',
    dependencies: [
        dependency('gtk+-3.0'),
        dependency('gee-0.8'),
        dependency('gio-unix-2.0'),
        dependency('libgnome-menu-3.0'),
        #dependency('libm17n-dev')
    ],

    c_args: [
        '-DGMENU_I_KNOW_THIS_IS_UNSTABLE',
    ],

    install: true
)

Compiling that returns:

Dependency libm17n-dev found: NO (tried pkgconfig and cmake)
meson.build:5:4: ERROR:  Dependency "libm17n-dev" not found, 
tried pkgconfig and cmake

sudo apt install libm17n-dev

gives:

libm17n-dev is already the newest version (1.8.0-2)

Am I on the right track?

That’s a linker error - basically your meson.build needs to link with “-lm” in your c-arguments statement

e.g.

BudgieShowTimeCArgs = [
'-include',
'config.h',
'-lm',
'-DWNCK_I_KNOW_THIS_IS_UNSTABLE'
]

Compiling you entire solution returns:

meson.build:5:4: ERROR:  
All keyword arguments must be after positional arguments.

This solution:

   c_args: [
        '-include',
        'config.h',
        '-lm',
        '-DWNCK_I_KNOW_THIS_IS_UNSTABLE'
    ],

returns:

fatal error: config.h: No such file or directory

And this :

    c_args: [
        '-include',
        #'config.h',
        '-lm',
        '-DWNCK_I_KNOW_THIS_IS_UNSTABLE'
    ],

returns:

cc1: fatal error: -Wl,--start-group: No such file or directory

that was just an example - to take your bit of code and amending it:

c_args: [
  '-DGMENU_I_KNOW_THIS_IS_UNSTABLE',
  '-lm'
],

Compiling that returns:

 /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols:
 DSO missing from command line

Your dependencies also need to say it needs the math module:

dependencies: [
        dependency('gtk+-3.0'),
        dependency('gee-0.8'),
        dependency('gio-unix-2.0'),
        dependency('libgnome-menu-3.0'),
        meson.get_compiler('c').find_library('m', required: false)
    ],

Cool … compiling went ok, thanks for the aid and the patience.

Running the app, I get an error:

  Segmentation fault (core dumped)

Is this related to the meson compiler?

Very unlikely.

This is likely to be a coding issue. You will need to add things like

message('have you got here yet');

Throughout bits if the code you suspect could be at issue until you narrow down the problem area

Thanks, David. A big project like Slingshot is maybe not the best to start with getting into Vala, but I just go for it.

Have a pleasant day.