-2

All the libs and dependencies are correct installed on my linux box. i can compile my test program with libwnck-3.0 in a simple make file:

 LDFLAGS = -lX11 `pkg-config  --cflags --libs gtkmm-3.0 libwnck-3.0 `
 CPPFLAGS =  -g -Wall -Wno-reorder -std=c++11 `pkg-config  --cflags gtkmm-3.0 libwnck-3.0`

OUTPUTDIR = bin

# Macro that uses the backslash to extend to multiple lines.
OBJS =  \
 main.o \
 $(NULL)

all:$(OBJS)
    $(CC) $(CPPFLAGS) -o$(OUTPUTDIR)/$(APPNAME) $(OBJS) $(LDFLAGS)

main.o:main.cpp 
        $(CC) -I$(INCLUDE) $(CPPFLAGS) -c main.cpp

...

the point is that to compile and link libwnck-3.0 i need to use: pkg-config --cflags -libs libwnck-3.0

the g++ compiler will compile and link my program without problems. But how i can do this with autotools Makefile.am?

here the main.cpp sample:

#define WNCK_I_KNOW_THIS_IS_UNSTABLE  1

#include <libwnck/libwnck.h>
#include <gtkmm.h>

int main(int argc, char *argv[])
{
    gdk_init (&argc, &argv);

    //check if libwnck works     
    WnckScreen* wnckscreen = wnck_screen_get_default();

    Gtk::Main kit(argc, argv);
    Gtk::Window mainWindow;
    Gtk::Button button("Click here");
    mainWindow.set_title("GTKmm Demo");
    mainWindow.set_border_width(4);
    mainWindow.set_default_size(200, 50);
    mainWindow.add(button);
    button.show();
    Gtk::Main::run(mainWindow);



    return 0;

}

and here the Automake test Makefile.am:

bin_PROGRAMS = testprogram
testprogram_SOURCES =  main.cpp 
# that is for gtkmm
testprogram_CPPFLAGS = $(GTKMM_CFLAGS)
# the include for libwnck-3.0
testprogram_CPPFLAGS += -I/usr/include/libwnck-3.0
testprogram_CPPFLAGS = $(GTKMM_CFLAGS)
# Linker flags 
testprogram_LDFLAGS =`pkg-config --cflags  --libs gtkmm-3.0 libwnck-3.0`

after run autogen.sh, ./configure and make, it compiles gtkmm but i get a link error: undefine reference to wnck_screen_get_default() The linker can't find the libwnck-3.0 package. ;o(

I have trying many variations and spend days on google without success.

Thank you in advance for any help!

yoo
  • 11
  • 1

1 Answers1

1

You should use PKG_CHECK_MODULES to check for the presence of the needed libraries, and just use WNCK_LIBS and WNCK_CFLAGS to link it in.

Of course you should use _LDADD, and not _LDFLAGS to pass the libraries, as those have different semantics.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15
  • yes, PKG_CHECK_MODULES solve the problem. Thanks! ;o) – yoo Jan 25 '17 at 20:40
  • Be careful about PKG_CHECK_MODULES though, using it incorrectly will make it very difficult for users to cross-compile your program or library (ie, compilation and linking against versions of dependencies other than thos installed by you OS' package manager) – Gunee Dec 01 '17 at 10:05