d3pd
d3pd

Reputation: 8315

how to write makefile that adds libraries after source

I have been supplied with the following makefile:

CXX=g++
CXXFLAGS=-std=c++11 -g -O2
LDFLAGS=-ltbb

EXE=$(basename $(wildcard *.cc))

all: $(EXE)

clean:
    rm -fr $(EXE) *.dSYM

I am new to makefiles and In order to get it working in Ubuntu, I need to modify it such that the LDFLAGS comes after the source file in the compile command. How can I do this? My attempt is as follows:

CXX=g++
CXXFLAGS=-std=c++11 -g -O2
LDFLAGS=-ltbb

SRCS=$(wildcard *.cc)
EXES=$(subst .cc,,$(SRCS))

all: $(EXES)
    $(CXX) $(CXXFLAGS) $(SRCS) $(LDFLAGS) -o $(EXES)

clean:
    rm -fr $(EXE) *.dSYM

Upvotes: 0

Views: 102

Answers (1)

Sleafar
Sleafar

Reputation: 1526

Libraries should be added to LDLIBS instead of LDFLAGS. Try this in your original makefile:

LDLIBS=-ltbb

See here for reference.

Upvotes: 1

Related Questions