ihsoy ih
ihsoy ih

Reputation: 1018

How to build library and link it with sources with Make

I'm still quite new to make. I am trying to compile a project in which maketest.cpp and maketest.hpp rests on Users/wen/Projects/maketest with the Makefile itself. Problem is, I want to also compile and link the source files (.cc and .hh) in Users/wen/Projects/include/bigint.

# Macros

INCLUDE = -I/Users/wen/Projects/include/bigint
LIBS =

CC = g++
override FLAGS += -O2

HEADERS= $(wildcard *.hpp) $(wildcard Users/wen/Projects/include/bigint/*.hh) 

# EXE Name
INSTALL = maketest

CC_FILES = %.cpp Users/wen/Projects/include/bigint/%.cc
OBJ_FILES = maketest.o $(wildcard Users/wen/Projects/include/bigint/*.o)

# Rules

$(INSTALL): $(OBJ_FILES)
    $(CC) $(FLAGS) $^ -o $@ $(LIBS)

%.o: $(CC_FILES) $(HEADERS)
    $(CC) $(FLAGS) $(INCLUDE) -c $< -o $@

# Installation types

install: $(INSTALL)

release:
    @echo "Re-run with parameter:"
    @echo "FLAGS=-D_RELEASE"

debug:
    @echo "Re-run with parameter:"
    @echo "FLAGS=-D_DEBUG"

# Cleaning up

clean:
    rm -f $(OBJ_FILES) $(INSTALL)

The code compiles maketest.cpp and links it, but not bigint.

What will be the right way to build and link the files from Users/wen/Projects/include/bigint? Many thanks!

Upvotes: 0

Views: 89

Answers (1)

ihsoy ih
ihsoy ih

Reputation: 1018

I figured it out at the end, thank you Jay. The problem was I forgot a slash at the front of Users/wen/Projects/include/bigint, so it was not searching from root but instead the project folder. Now it works!

Try explicitly specifying one of the files from bigint in OBJ_FILES (perhaps "bigint.o" ?). I don't think your wildcard is getting what you want.

Upvotes: 1

Related Questions