[Noob question] Compiling application with more than one file

I’m completely new to GTK and I’ve been following the reference manual to get acquainted with the syntax and structure. I had no trouble following the first three sections of the overview (Basics, Packing, Building user interfaces), but I’m hitting a bit of a wall in the fourth section (Building applications).

Following the relevant source code on the GitLab page, we see that suddenly there are multiple files involved, such as exampleapp.h, exampleapp.desktop, main.c, makefile.am, most of which aren’t explicitly mentioned in the reference manual. I figured that I would simply download the files, and naively attempt to compile a .c file to see if I get a working application in the first place, before tweaking around some settings in the various files to see what it does. But doing so gives obvious errors: attempting to compile main.c in application1 of the source code, for instance, returns the error

main.c:(.text+0x19): undefined reference to `example_app_new’

This suggests to me that I’m fundamentally misunderstanding a part of the compiling process. What am I missing?

NB. I’m sure it’ll be apparent from the question but just for clarity I add that I’m also fairly new to C as a whole. In any case I’ve never gone beyond writing a single C script and compiling that file individually.

Have you looked at the Makefile that ships with the source code?


This one builds the first example. It ends up running the following commands:

gcc -o main.o -I... main.c
gcc -o exampleapp.o -I... exampleapp.c
gcc -o exampleappwin.o -I... exampleappwin.c
gcc -o exampleapp main.o exampleapp.o exampleappwin.o -lgtk4

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.