(C++) glibmm won't link on Ubuntu/Oneiric

692 views Asked by At

I have problems clinking simplest program on Ubuntu/Oneiric:

#include <glibmm/ustring.h>

int main()
{
    Glib::ustring s = "Test string";
}

using Makefile

PACKAGES=glibmm-2.4 glib-2.0 gtkmm-3.0 gtk+-3.0
CC=g++
CFLAGS=`pkg-config --cflags $(PACKAGES)` --std=c++0x
LD=g++
LDFLAGS=`pkg-config --libs $(PACKAGES)`

build: ./main

run: build
    ./main

clean:
    rm ./main.o

rebuild: clean build

./main: ./main.o
    $(LD) $(LDFLAGS) ./main.o -o ./main

./main.o: ./main.cc
    $(CC) $(CFLAGS) ./main.cc -c -o ./main.o

on make following errors appears:

./main.o: In function `main':
main.cc:(.text+0x15): undefined reference to `Glib::ustring::ustring(char const*)'
main.cc:(.text+0x21): undefined reference to `Glib::ustring::~ustring()'
collect2: ld returned 1 exit status
make: *** [main] Error 1

On Ubuntu/Maverick the exactly same code links well with exactly same file... if using ld on main.o it links successfully too but (as it was expected) _start is missing...

Any suggestions?

1

There are 1 answers

0
Some programmer dude On

Try changing the relevant lines to this:

LDFLAGS=`pkg-config --libs-only-L --libs-only-other $(PACKAGES)`
LIBS=`pkg-config --libs-only-l $(PACKAGES)`

# ...

./main: ./main.o
    $(LD) $(LDFLAGS) ./main.o -o ./main $(LIBS)

The reason is that the linker may search libraries in the order they are given on the command line, so they should always be placed last to be safe.