wisuzu
wisuzu

Reputation: 11

Makefile and library bad dependencies?

I want to use some opencv classes on my gtkmm/glade/c++ . After including any opencv code it work just fine, but if I add the opencv to libs like this: LIBS = 'pkg-config ... opencv --libs' the application stop working. In the first line of the main ( Gnome::Gda::init(); ) it crashes with a Segmentation Fault

Makefile

LD = g++
LIBS = `pkg-config gtkmm-2.4 glibmm-2.4 libgdamm-4.0 --libs`
CPPFLAGS = `pkg-config gtkmm-2.4 glibmm-2.4 libgdamm-4.0 --cflags`

OBJS = main.o TreeviewImages.o MainWindow.o FormDialog.o DBUtil.o

all: build

build: $(OBJS)
    $(LD) $(LIBS) $(OBJS) -o cish

main.o: main.cpp
   g++ $(CPPFLAGS) -c main.cpp

MainWindow.o: MainWindow.cpp MainWindow.h DBUtil.h FormDialog.h
    g++ $(CPPFLAGS) -c MainWindow.cpp

TreeviewImages.o: TreeviewImages.cpp TreeviewImages.h
    g++ $(CPPFLAGS) -c TreeviewImages.cpp

FormDialog.o: FormDialog.cpp FormDialog.h DBUtil.h
    g++ $(CPPFLAGS) -c FormDialog.cpp

DBUtil.o: DBUtil.cpp DBUtil.h
    g++ $(CPPFLAGS) -c DBUtil.cpp

clean:
    rm -f cish $(OBJS)

Any lead/hint/help will be appreciated!

Upvotes: 0

Views: 451

Answers (1)

Milan
Milan

Reputation: 15849

It makes a big difference where put your libraries when linking.

If you have a library libexample, using:

 g++ -lexample myprog2.o

will fail to to load the library functions if myprog2 is referencing them.

Instead use:

g++ myprog2.o -lexample 

That is to say, add the $(LIBS) after the reference to object files.

Upvotes: 2

Related Questions