Makefile with gsl libraries

I am trying to create a .exe file from my .cpp with ROOT and GSL libraries. My Makefile is:

ObjSuf = o
SrcSuf = C
DllSuf = so
OutPutOpt = -o
ROOTLIBS = $(shell root-config --libs)
ROOTGLIBS = $(shell root-config --glibs)
ROOTCFLAGS = $(shell root-config --cflags)

CXX = g++
CXXFLAGS = -O2 -Wall -fPIC
LD = g++
SOFLAGS = -shared
LIBS = $(ROOTLIBS) $(ROOTGLIBS)
CXXFLAGS += $(ROOTCFLAGS) -Iinclude
LIBS += -lSpectrum -lMinuit

macro.exe: macro.o
$(CXX) $(CXXFLAGS) $(ALLLIBS) $(ALLEXES) -o macro.exe macro.o $(LIBS)
@echo “Done”

clean:
@rm -f *.o *~ core

As suggested in other questions in the forum, I added at the top of my macro.cpp:

R__LOAD_LIBRARY(libgsl)

R__LOAD_LIBRARY(gsl)

Among other libraries, I also have

#include <gsl/gsl_matrix.h>

#include <gsl/gsl_odeiv2.h>

I followed similar threads about GSL and Makefile to edit my Makefile, but nothing worked (here I posted the Makefile that someone sent me and is supposed to work with ROOT libraries). The errors after typing make are endless, but the first lines are:

macro.cpp:1:16: error: expected constructor, destructor, or type conversion before ‘(’ token
R__LOAD_LIBRARY(libgsl);
^
macro.cpp:2:16: error: expected constructor, destructor, or type conversion before ‘(’ token
R__LOAD_LIBRARY(gsl); //To make gsl work

I tried typing those lines in a ROOT terminal, and it worked fine. I don’t know what the problem can be.

How can I correct my Makefile to make it work?

In your source code file, before the very first line with any “R__*” macro, you must “#include” anything from ROOT (so that these macros are defined), e.g. add:

#include "Rtypes.h"

In your “Makefile” add:

LIBS += $(shell gsl-config --libs)

Just for future reference purposes … Compile Macro with GSL libraries

It works! Thank you.