Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:02:10+00:00 2026-05-28T07:02:10+00:00

I am trying to create python bindings to a vala library using the following

  • 0

I am trying to create python bindings to a vala library using the following IBM tutorial as a reference.

My initial directory has the following two files:

test.vala

using GLib;

namespace Test {

   public class Test : Object {
       public int sum(int x, int y) {
           return x + y;
       }
   }

}

test.override

%%
headers
#include <Python.h> 
#include "pygobject.h"
#include "test.h"
%%
modulename test
%%
import gobject.GObject as PyGObject_Type
%%
ignore-glob
  *_get_type
%%

and try to build the python module source test_wrap.c using the following code

build.sh

#/usr/bin/env bash

valac test.vala -CH test.h
python /usr/share/pygobject/2.0/codegen/h2def.py test.h > test.defs
pygobject-codegen-2.0 -o test.override -p test test.defs > test_wrap.c

However, the last command fails with an error

$ ./build.sh 
Traceback (most recent call last):
  File "/usr/share/pygobject/2.0/codegen/codegen.py", line 1720, in <module>
    sys.exit(main(sys.argv))
  File "/usr/share/pygobject/2.0/codegen/codegen.py", line 1672, in main
    o = override.Overrides(arg)
  File "/usr/share/pygobject/2.0/codegen/override.py", line 52, in __init__
    self.handle_file(filename)
  File "/usr/share/pygobject/2.0/codegen/override.py", line 84, in handle_file
    self.__parse_override(buf, startline, filename)
  File "/usr/share/pygobject/2.0/codegen/override.py", line 96, in __parse_override
    command = words[0]
IndexError: list index out of range

Is this a bug in pygobject, or is something wrong with my setup? What is the best way to call code written in vala from python?

EDIT:
Removing the extra line fixed the current problem, but now as I proceed to build the python module, I am facing another problem. Adding the following C file to the existing two in the directory:

test_module.c

#include <Python.h>

void test_register_classes (PyObject *d);
extern PyMethodDef test_functions[];

DL_EXPORT(void)
inittest(void)
{
  PyObject *m, *d;
  init_pygobject();
  m = Py_InitModule("test", test_functions);
  d = PyModule_GetDict(m);
  test_register_classes(d);
  if (PyErr_Occurred ()) {
      Py_FatalError ("can't initialise module test");
  }
}

and building with the following script

build.sh

#/usr/bin/env bash

valac test.vala -CH test.h
python /usr/share/pygobject/2.0/codegen/h2def.py test.h > test.defs
pygobject-codegen-2.0 -o test.override -p test test.defs > test_wrap.c

CFLAGS="`pkg-config --cflags pygobject-2.0` -I/usr/include/python2.6/ -I."
LDFLAGS="`pkg-config --libs pygobject-2.0`"

gcc $CFLAGS -fPIC -c test.c 
gcc $CFLAGS -fPIC -c test_wrap.c 
gcc $CFLAGS -fPIC -c test_module.c
gcc $LDFLAGS -shared test.o test_wrap.o test_module.o -o test.so

python -c 'import test; exit()'

results in an error:

$ ./build.sh 
***INFO*** The coverage of global functions is 100.00% (1/1)
***INFO*** The coverage of methods is 100.00% (1/1)
***INFO*** There are no declared virtual proxies.
***INFO*** There are no declared virtual accessors.
***INFO*** There are no declared interface proxies.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: ./test.so: undefined symbol: init_pygobject

Where is the init_pygobject symbol defined? What have I missed linking to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:02:11+00:00Added an answer on May 28, 2026 at 7:02 am

    You can go with GObject Introspection.

    This repository contains samples how to auto-bind vala libraries to other languages:

    https://github.com/antono/vala-object

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create python bindings to a vala library using pygi with
I'm trying to create python bindings for source-highlight-qt using sip. I'm working on ubuntu
I'm trying to create a python program (using pyUNO ) to make some changes
I'm trying to create an xml entry that looks like this using python and
I am trying to create a simple python extension module. I compiled the following
I'm trying to create a custom TCP stack using Python 2.6.5 on Windows 7
I am attempting to create python bindings for some C++ code using swig. I
I'm trying to use VLC's python bindings to create my own little video player.
I'm trying to create a python script that logs into JIRA using their REST
I am trying to create a csv file using python that is truly Excel-compatible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.