Linking error when trying to access private struct of subclassed widget from other sources

img-timeline.h:

G_BEGIN_DECLS

struct _ImgTimeline
{
  /*< private >*/
 GtkLayout da;
};

// some other stuff

#define IMG_TIMELINE_TYPE img_timeline_get_type()
G_DECLARE_FINAL_TYPE(ImgTimeline, img_timeline, IMG, TIMELINE,    GtkLayout)

G_END_DECLS

img-timeline.c:

#include "img_timeline.h"
G_DEFINE_TYPE_WITH_PRIVATE(ImgTimeline, img_timeline, GTK_TYPE_LAYOUT)

//A lot of other stuff

main-window.c:1326 where I get the linking error:

ImgTimelinePrivate *priv = img_timeline_get_instance_private(widget);

/usr/bin/ld: imagination-main-window.o: in function img_media_model_remove_media': /home/gt/projects/imagination/src/main-window.c:1326: undefined reference to img_timeline_get_instance_private’

If I move the G_DEFINE_TYPE macro inside the img-timeline.h I get loads of compiler errors.

Does someone have a clue please?

You can’t do that.

Options:

  • Define public getter/setter functions (best option)
  • Use G_DEFINE_TYPE instead of G_DEFINE_TYPE_WITH_PRIVATE, move the instance struct to a header (so it is public instead of private), and stop using the get_instance_private() (not recommended)
1 Like

Thank you so much indeed for replying! I solved through an intermediary function.

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