Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to modify the Makefile to include/link GSL library?

195 views
Skip to first unread message

fl

unread,
Jan 23, 2017, 3:13:24 PM1/23/17
to
Hi,

I am learning GSL library on my Ubuntu 16.04LTS computer. GSL is successfully
installed. It can build a simple .cpp file:

g++ main.cpp -L/home/jeff/gsl/lib -I/home/jeff/gsl/include -lgsl -lgslcblas -lm


That is, GSL is installed on directory:
/home/jeff/gsl





Now, I download a tutorial project, which needs to build the library first.
It instructs to run:

make library

on a command line under the top tutorial directory.


The tutorial does say the Makefile needs to modify for GSL library, but
I don't know how to do it after several trials.

Below is the head Makefile under the tutorial directory:


--top directory, Makefile:

.PHONY: docs clean distclean examples

default: libraries examples

all: libraries docs examples

clean:
make -Csrc clean
make -Cexamples clean
-rm *~
-rm */*~

distclean: clean
-rm bin/*
-rm lib/*
-rm -Rf doc/*

libraries:
make -Csrc all
....

This is the Makefile under top/src/ directory:



--src directory Makefile:

include ../Makefile.in

SMCC = rng.cc history.cc smc-exception.cc
SMCO = rng.o history.o smc-exception.o

all: libsmctc.a

.PHONY: clean

clean:
-rm *.o
-rm *.a
-rm *~

libsmctc.a: $(SMCC) Makefile
$(CC) $(CCFLAGS) -c -I../include $(SMCC)
ar rcs libsmctc.a $(SMCO)
cp libsmctc.a ../lib
/////////////////

When I run my modified Makefile, it gives such errors:

$ make libraries
make -Csrc all
make[1]: Entering directory '/home/jeff/workspace/smctc-1.0/src'
g++ -O3 rng.cc history.cc smc-exception.cc
rng.cc:7:18: fatal error: rng.hh: No such file or directory
compilation terminated.
history.cc:1:20: fatal error: smctc.hh: No such file or directory
compilation terminated.
smc-exception.cc:1:28: fatal error: smc-exception.hh: No such file or directory



Anyhow, I cannot figure out the right way to modify Makefile.
Can you help me out?


Thanks.

fl

unread,
Jan 23, 2017, 4:09:35 PM1/23/17
to
In fact, I've been learning makefile a few times. Now the makefiles in Ubuntu
are more involved, for it having a subdirectory makefile.

In the following snippet, I know libsmctc.a is a make target.
But '$(SMCC) Makefile' is puzzling. $(SMCC) is like a parameter to put into
Makefile?

Second, $(CC) and $(CCFLAGS) have default values in the Makefile?
Thanks again.

-----------------
SMCC = rng.cc history.cc smc-exception.cc
SMCO = rng.o history.o smc-exception.o

...

Riccardo Zanella

unread,
Jan 23, 2017, 4:13:43 PM1/23/17
to
Il 23/01/17 21:13, fl ha scritto:
(I suppose you are compiling https://github.com/matsengrp/smctc)

Seems that compilation command for libsmctc.a target can't find rng.hh
(and smctc.hh and smc-exceptions.hh). Such include files are not GSL,
and should be in include (-I../include was meant to find those files).

For GSL:
change Makefile.in by adding:
-I path_to_gsl_includes to CCFLAGS
-L path_to_gsl_libs in LFLAGS just before -lgsl

Riccardo

Jorgen Grahn

unread,
Jan 23, 2017, 5:01:43 PM1/23/17
to
On Mon, 2017-01-23, fl wrote:
> On Monday, January 23, 2017 at 3:13:24 PM UTC-5, fl wrote:
>> Hi,
...
> In fact, I've been learning makefile a few times. Now the makefiles
> in Ubuntu are more involved, for it having a subdirectory makefile.
>
> In the following snippet, I know libsmctc.a is a make target.
> But '$(SMCC) Makefile' is puzzling. $(SMCC) is like a parameter to put into
> Makefile?

You mean

libsmctc.a: $(SMCC) Makefile

Have you tried reading the Make manual? $(SMCC) is variable expansion,
much like C++ macros. So that's the same thing as

libsmctc.a: rng.cc history.cc smc-exception.cc Makefile

That looks like a really badly-written Makefile. A static library
should simply depend on the object files you want to put into it:

libsmctc.a: rng.o history.o smc-exception.o
$(AR) rcs $@ $^

> Second, $(CC) and $(CCFLAGS) have default values in the Makefile?

Gnu Make (which you're using, since you're on Linux) predefines some
names. But something is a bit off here:

- $(CC) is the name of the C compiler; the C++ compiler is called $(CXX).
- $(CCFLAGS) looks like one of the predefined names, but the C compiler
options are called $(CFLAGS) and the C++ ones $(CXXFLAGS).

A Makefile can use any names it wants, but not choosing the standard
names certainly makes things harder.

> -----------------
> SMCC = rng.cc history.cc smc-exception.cc
> SMCO = rng.o history.o smc-exception.o
>
> ...
>
> libsmctc.a: $(SMCC) Makefile
> $(CC) $(CCFLAGS) -c -I../include $(SMCC)
> ar rcs libsmctc.a $(SMCO)
> cp libsmctc.a ../lib

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
0 new messages