0

i'm trying to use the boost_math libs on OS X (i'm not using Xcode), specifically the one containing the error function

I downloaded and compiled boost_1_60_0 myself (using bootstrap.sh and following the instructions.) I didn't use home-brew or something else, which might be why my installation seems so screwed up.

What i'm trying to include in my Szabo.hpp is this:

#include <boost/math/special_functions/erf.hpp>

My makefile goes like this:

LIB_FLAGS = -L/Documents/boost_1_60_0/stage/lib -lboost_math
ALL_OBJECTS = main.o Gaussienne.o Grille.o Szabo.o

all:  $(ALL_OBJECTS)
    g++ -o hydrogene $(ALL_OBJECTS) $(LIB_FLAGS)

Gaussienne.o: Gaussienne.cpp
    g++ -o Gaussienne.o -c Gaussienne.cpp -W -Wall -ansi 

main.o: Gaussienne.hpp Grille.hpp main.cpp Szabo.o
    g++ -o main.o -c main.cpp -W -Wall -ansi 

Grille.o: Grille.cpp Gaussienne.cpp
    g++ -o Grille.o -c Grille.cpp -W -Wall -ansi

Szabo.o: Szabo.cpp Gaussienne.cpp
    g++ -o Szabo.o -c Szabo.cpp -W -Wall -ansi

clean:
    rm -rf *.o

mrproper: clean
    rm -rf hydrogene

I get no linking error from g++, however i got:

 In file included from Szabo.cpp:12:
./Szabo.hpp:21:10: fatal error: 'boost/math/special_functions/erf.hpp' file not found
#include <boost/math/special_functions/erf.hpp>
         ^
1 error generated.

Can you please provide help on how to fix this? Thanks in advance

Ok so apparently likes this, it works:

LIB_FLAGS = -L/Users/devolution/Documents/boost_1_60_0/stage/lib -lboost_math_tr1

I_FLAGS = -I/Users/devolution/Documents/boost_1_60_0/ ALL_OBJECTS = main.o Gaussienne.o Grille.o Szabo.o

all:  $(ALL_OBJECTS)
    g++ -o hydrogene $(ALL_OBJECTS) $(LIB_FLAGS)

Gaussienne.o: Gaussienne.cpp
    g++ -o Gaussienne.o -c Gaussienne.cpp -ansi ${I_FLAGS}

main.o: Gaussienne.hpp Grille.hpp main.cpp Szabo.o 
    g++ -o main.o -c main.cpp -ansi ${I_FLAGS}

Grille.o: Grille.cpp Gaussienne.cpp
    g++ -o Grille.o -c Grille.cpp  -ansi ${I_FLAGS}

Szabo.o: Szabo.cpp Gaussienne.cpp
    g++ -o Szabo.o -c Szabo.cpp -ansi ${I_FLAGS}

.PHONY: clean mrproper
clean:
    rm -rf *.o

mrproper: clean
    rm -rf hydrogene

Is there a way to pass I_FLAGS?

Devolution
  • 31
  • 6
  • You need to tell your compiler where to find that file path. You need the appropriate `-I` argument (like you have the `-L` argument already). – Etan Reisner Apr 13 '16 at 12:24
  • Yeah i thought so but i see a lot of boost users have a folder include at the root of the boost folder, strange thing is i don't, so i don't really know what to put inside -I. I tried with `-I/Documents/boost_1_60_0/` and `-I/Documents/boost_1_60_0/boost` but it doesn't work – Devolution Apr 13 '16 at 12:34
  • If you don't have a `boost` folder at the root of your include tree that's slightly odd possibly (but possibly not) and then you can't include it in the path you use with `#include` or you create the directory (as a symlink if nothing else) so that you can use it. – Etan Reisner Apr 13 '16 at 12:39
  • I have the correct boost 1_60 architecture i just checked on the documentations. My headers are inside boost_1_60_0/boost/math etc.. but it seems the compiler doesn't understand to search there even with the -I line. – Devolution Apr 13 '16 at 13:00
  • What did you pass as your `-I` argument to the compiler? And on what command? – Etan Reisner Apr 13 '16 at 13:06
  • This is how i pass -I to the compiler : `LIB_FLAGS = -L/Users/devolution/Documents/boost_1_60_0/stage/lib -lboost_math-mt I_FLAGS = -I/Users/devolution/Documents/boost_1_60_0/ ALL_OBJECTS = main.o Gaussienne.o Grille.o Szabo.o all: $(ALL_OBJECTS) g++ -o hydrogene $(ALL_OBJECTS) $(LIB_FLAGS) ${I_FLAGS}` – Devolution Apr 13 '16 at 13:11
  • @EtanReisner: No, boost should not be in your source tree. It should be in the system's general includes location. – Lightness Races in Orbit Apr 13 '16 at 13:35
  • ...and then you should not need `-I`. – Lightness Races in Orbit Apr 13 '16 at 13:43
  • @LightnessRacesinOrbit I didn't indicate it should be in the program's source tree. The OP did say they compiled it themselves and it is *not* in the system location so `-I` is necessary (and that's fine). – Etan Reisner Apr 13 '16 at 15:14
  • @Etan It's not fine! You're hardcoding the location of a third-party dependency, which gives your codebase approximately zero portability. The solution is to make it so that the headers _are_ in the system location. (As for the tree comment, sorry yeah I misinterpreted your _"If you don't have a boost folder at the root of your include tree that's slightly odd possibly"_) – Lightness Races in Orbit Apr 13 '16 at 16:25
  • It is fine as long as the flag is overridable. This is what control over `CFLAGS`, `LDFLAGS`, etc. in makefiles is **for**. It is why they are in the default make rules. It is why pkg-config projects and the autotools use/support `PKG_CFLAGS` and `PKG_LIBS`, etc. variables. Installing everything you intend to compile against to system-wide locations is neither useful (in the general case) nor necessary (or even necessarily a good idea). – Etan Reisner Apr 13 '16 at 16:41
  • I completely and entirely disagree. – Lightness Races in Orbit Apr 13 '16 at 18:57

1 Answers1

0

You've compiled Boost's separately-compiled libraries, which is great, but you didn't copy the headers to your toolchain's include path. Indeed, most of Boost is comprised of header-only libraries, so this is arguably the more crucial step of installing Boost.

The internet tells me you may be able to find the default header search path with the following command at shell:

gcc -x c++ -v -E /dev/null

(https://stackoverflow.com/a/19852298/560648)

When you find it, copy the distribution's boost subdirectory to it.

And, yes, having home-brew install Boost for you would have been much easier… probably one command!

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055