views:

87

answers:

1

Hello,

I have 3 files in my gtk+ app:

main.c:

#include <gtk/gtk.h>
#include <glib/gi18n.h>

#include "mainwindow.h"

int main(int argc, char** argv)
{
    MainWin*      win;
    GError* err = NULL;
    int a = 0;
    a = some_foo();
    gtk_main();
    return 0;
}

mainwindo.h

#include <gtk/gtk.h>


typedef struct _MainWin
{
    GtkWindow parent;

} MainWin;

GtkWidget* main_win_new();

int some_foo();

MainWindow.c

#include "mainwindow.h"


int some_foo()
{
  return 1;
}

When i try to call some_foo in main function, and try to compile i see error: undefined reference to `some_foo'. What's wrong?

Thank you.

+3  A: 

You are probably not including MainWindow.c in your build. E.g. in the shell it could look like this:

gcc $ALL_THE_FLAGS main.c MainWindow.c
Georg Fritzsche
I compile with makefile. This makefile generated by autoconf. And it very big. How can o include mainwindow.c file?
shk
You have to look in your `Makefile.in` in that case and add the source and the object file there. If that file is shorter, maybe copy it into the question? Alternatively there are services like pastebin. @sterh
Georg Fritzsche
Makefile.in - http://pastebin.com/t1Ae1X5P
shk
@sterh: could you add your Makefile.am file? it should be more readable
Hasturkun
Makefile.am - http://pastebin.com/eGUcerFn
shk
@sterh: In your `Makefile.am` you've got `MainWindow.c` in lower case (`mainwindow.c`), but in your question you've got it capitalized - are you sure you haven't got another file called `mainwindow.c` which is being built instead? (I'm assuming you're on linux or some similar system where filenames are case sensitive).
Mike Dinsdale
@sterh The Makefile is not generated by autoconf. The makefile is generated by the configure script from Makefile.in, and the Makefile.in is generated by automake.
William Pursell