2

I am currently working on a project in vala and I am having trouble getting the project to compile. The files pass through valac, just fine but then I get this error:

C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x437): undefined reference to gtk_source_view_new' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x48a): undefined reference togtk_source_view_set_auto_indent' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x4a2): undefined reference to gtk_source_view_set_indent_on_tab' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x4ba): undefined reference togtk_source_view_set_show_line_numbers' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x4d2): undefined reference to gtk_source_view_set_highlight_current_line' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0x4ea): undefined reference togtk_source_view_set_insert_spaces_instead_of_tabs' C:\Users\Andrew\AppData\Local\Temp/ccEYx9mD.o:EditorWindow.vala.c:(.text+0xf74): undefined reference to `gtk_source_view_get_type'

The code for the file in question that is failing is as follows:

using Gtk;
using Gtk.Stock;
using Gdk;

public class EditorWindow : GLib.Object
{
    public Gtk.SourceView EditorWindow {get;set;}
    public HBox TabHeader {get;set;}
    private Gtk.Image icon {get;set;}
    private Label name {get;set;}
    private Button closeButton {get;set;}
    public unowned Notebook parent {get;set;}


    public EditorWindow(File? file = null, Notebook parent)
    {
        //Interperet file data
        if(file == null)
        {
            this.name = new Label("testPage.cs");
        }
        else
        {
            //get all necessary file data
        }

        this.TabHeader = new HBox(false, 0);
        //this.name = new Label("testPage.cs");
        this.closeButton = new Button();
        this.closeButton.set_relief(ReliefStyle.NONE);
        this.closeButton.set_focus_on_click(false);
        this.closeButton.add(new Gtk.Image.from_stock(Gtk.Stock.CLOSE, IconSize.MENU));
        this.icon = new Gtk.Image.from_stock(Gtk.Stock.FILE, IconSize.MENU);
        this.TabHeader.pack_start(this.icon, false, false, 0);
        this.TabHeader.pack_start(this.name, true, true, 0);
        this.TabHeader.pack_start(this.closeButton, false, false, 0);
        this.EditorWindow = new Gtk.SourceView();
        this.EditorWindow.auto_indent = true;
        this.EditorWindow.indent_on_tab = true;
        this.EditorWindow.show_line_numbers = true;
        this.EditorWindow.highlight_current_line = true;
        this.EditorWindow.insert_spaces_instead_of_tabs = false;
        //parent.append_page(this.EditorWindow, this.TabHeader);

        //Read libraries to register objects and methods

        //Parse all lines and provide labels


    }

    public void ParseLibraries()
    {

    }

    public void ParseLocalFiles()
    {

    }

    public void ParseProjectFiles()
    {

    }
}

The file fails out after those five lines and says collect2: ld returne 1 exit status.

Any idea how to solve this problem? Any help at all would be appreciated.

EDIT

The command line compilation that I used was: valac Main.vala GUI.vala EditorWindow.vala -o Valarian.exe --enable-checking --pkg gtk+-2.0 --pkg gdk-2.0 --pkg gtksourceview-2.0 --thread. I am running this on windows, so I am using gtk/gdk/sourceview 2.0.

Andrew Benton
  • 506
  • 2
  • 12
  • You should inform valac that you are using the package GTK. What is the command line that you use for compilation? – user1284631 Dec 17 '12 at 11:10
  • 1
    I used `valac Main.vala GUI.vala EditorWindow.vala -o Valarian.exe --enable-checking --pkg gtk+-2.0 --pkg gdk-2.0 --pkg gtksourceview-2.0 --thread`. – Andrew Benton Dec 17 '12 at 11:11
  • Try using: valac -o Valarian.exe --enable-checking --pkg gtk+-2.0 --pkg gdk-2.0 --pkg gtksourceview-2.0 --thread Main.vala GUI.vala EditorWindow.vala – user1284631 Dec 17 '12 at 11:15
  • Also, according to this (https://mail.gnome.org/archives/vala-list/2012-April/msg00069.html): You have to set environment variable PKG_CONFIG_PATH to point to where .pc files resides. Then tell valac what packages you want to use with --pkg=. eg: valac Gtk-01 Gtk-01.vala --pkg=gtk+-2.0 – user1284631 Dec 17 '12 at 11:17
  • I had the gtksourceview_2.0.pc residing in the directory specified by that path before posting the question. I also have the dll.a file for this package, though I don't know if that actually is needed and it is under a different path. – Andrew Benton Dec 17 '12 at 11:26
  • It should be needed. However, are you on sure that you are using 32-bit .dll on 32-bit Windows or 64-bit .dll on 64-bit Windows? – user1284631 Dec 17 '12 at 11:28
  • I am using the default valac, and the mingw is mingw32. I'm using Windows 7 x64 Home. I have written and run other Vala programs on this pc on the current configuration. I don't know what architecture the dll.a is using though. – Andrew Benton Dec 17 '12 at 11:31
  • Also, pass -X -mwindows flags to valac, like here: valac -X -mwindows --pkg gtk+-2.0 hellogtk.vala (see: https://live.gnome.org/Vala/ValaOnWindows) – user1284631 Dec 17 '12 at 11:31
  • I tried that and that only adds more errors in the form of `c:\vala-0.12.0\bin\ld.exe: cannot find -lcomdlg32`. Additionally that is only for hiding the console window when running GUI apps. I don't care yet if the extra console window is shown or not. – Andrew Benton Dec 17 '12 at 11:41

2 Answers2

0

MingW is a little odd when linking. It can needs the same library reference multiple times. First, try changing the order to gtksourceview, gtk, gdk. This may not be enough. MingW's linker, for complicated reasons, can't resolve circular references, so you have to specify the library multiple times. I use valac -C and then invoke:

i586-mingw32msvc-gcc -o mybin sources.c pkg-config --cflags --libs gconf-2.0 gtk+-2.0 glib-2.0 gtk+-2.0 glib-2.0 gtk+-2.0 glib-2.0

Note the ridiculous repetition of libraries. If you are building using the MingW cross compiler, you may also need to set the environment variable PKG_CONFIG_PATH=$(MING_ROOT)/lib/pkgconfig and pass, to pkg-config the argument --define-variable=prefix=$(MING_ROOT).

apmasell
  • 7,033
  • 19
  • 28
  • You do not need to repeat, you need to separate cflags from libs: http://mail.gnome.org/archives/gtk-app-devel-list/2010-February/msg00036.html – ntd Dec 18 '12 at 18:47
  • Can you give me what the actual command would be for separating cflags from libs? I'm also not using linux. Can you give me an example of what the actual command line would be to compile this, because I haven't been able to get it to work. – Andrew Benton Dec 20 '12 at 06:48
0

I don't like to answer my own question on here, but since we were looking in the wrong direction, here goes:

The problem that I was experiencing where the compiler was running into 'undefined reference' errors was caused by the manually applied namespace 'Gtk' before SourceView at the top of the EditorWindow class. Due to the nature of the Vala compiler, it did not throw an error because SourceView is under the Gtk namespace, but apparently something went wrong between valac and gcc. As soon as I changed Gtk.SourceView to SourceView, the program compiled.

Andrew Benton
  • 506
  • 2
  • 12