Error in compiling cmdstan (cstddef, string not found)


#1

Operating System: Ubuntu 16.04
Interface Version: CmdStan
Compiler/Toolkit: gcc

Not sure why i’m getting these errors on compilation when I have the C standard library installed on my computer in /usr/include/c++/5…

Long story short, it can’t find string and cstddef.

In file included from stan/src/stan/command/stanc_helper.hpp:4:
stan/src/stan/version.hpp:4:stan/src/stan/io/read_line.hpp:4:10: fatal error: 'istream' 10file:  not foundfatal error
: #include <istream>'string' file not found
#include <string>
         ^~~~~~~~~

         ^~~~~~~~
In file included from stan/src/stan/lang/grammars/expression07_grammar_inst.cpp:1:
In file included from stan/src/stan/lang/grammars/expression07_grammar_def.hpp:6:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/include/qi.hpp:16:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/home/qi.hpp:14:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/home/qi/action.hpp:14:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/home/qi/action/action.hpp:14:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/home/qi/meta_compiler.hpp:14:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/spirit/home/support/meta_compiler.hpp:15:
In file included from stan/lib/stan_math/lib/boost_1.64.0/boost/config.hpp:44:
stan/lib/stan_math/lib/boost_1.64.0/boost/config/select_stdlib_config.hpp:18:12: fatal error: 
      'cstddef' file not found
#  include <cstddef>
           ^~~~~~~~~
In file included from stan/src/stan/lang/grammars/statement_grammar_inst.cpp:1:
In file included from stan/src/stan/lang/grammars/statement_grammar_def.hpp:4:
In file included from stan/src/stan/lang/ast.hpp:5:
stan/src/stan/lang/ast/expr_type.hpp:5:10: fatal error: 'cstddef' file not found
#include <cstddef>
         ^~~~~~~~~
1 error generated.
makefile:86: recipe for target 'bin/cmdstan/stanc.o' failed
make: *** [bin/cmdstan/stanc.o] Error 1
make: *** Waiting for unfinished jobs....
1 error generated.
make/libstan:9: recipe for target 'bin/stan/lang/grammars/program_grammar_inst.o' failed
make: *** [bin/stan/lang/grammars/program_grammar_inst.o] Error 1
1 error generated.
make/libstan:9: recipe for target 'bin/stan/lang/grammars/expression07_grammar_inst.o' failed
make: *** [bin/stan/lang/grammars/expression07_grammar_inst.o] Error 1
1 error generated.
make/libstan:9: recipe for target 'bin/stan/lang/grammars/statement_grammar_inst.o' failed
make: *** [bin/stan/lang/grammars/statement_grammar_inst.o] Error 1

#2

Could you try commenting out

CXXFLAGS += -stdlib=libc++

In cmdstan/stan/lib/stan_math/make/detect_cc and see what happens?


#3

Great that worked – thanks!


#4

well, I still have problem on Ubuntu 14.04.4 LTS on which I have clang+±3.9.

$ make CXX=clang+±3.9 foo/bar
clang+±3.9 -Wall -I . -isystem stan/lib/stan_math/lib/eigen_3.3.3 -isystem stan/lib/stan_math/lib/boost_1.64.0 -isystem stan/lib/stan_math/lib/cvodes_2.9.0/include -std=c++1y -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I src -I stan/src -isystem stan/lib/stan_math/ -DEIGEN_NO_DEBUG -DFUSION_MAX_VECTOR_SIZE=12 -stdlib=libc++ -Wno-unused-function -Wno-uninitialized -DNO_FPRINTF_OUTPUT -pipe -c -O3 -o bin/cmdstan/stanc.o src/cmdstan/stanc.cpp
In file included from src/cmdstan/stanc.cpp:1:
In file included from stan/src/stan/command/stanc_helper.hpp:4:
stan/src/stan/version.hpp:4:10: fatal error: ‘string’ file not found
#include
^
1 error generated.

If I use g++, I would have

make CXX=g++ foo/bar
g++ -Wall -I . -isystem stan/lib/stan_math/lib/eigen_3.3.3 -isystem stan/lib/stan_math/lib/boost_1.64.0 -isystem stan/lib/stan_math/lib/cvodes_2.9.0/include -std=c++1y -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I src -I stan/src -isystem stan/lib/stan_math/ -DEIGEN_NO_DEBUG -DFUSION_MAX_VECTOR_SIZE=12 -stdlib=libc++ -Wno-unused-function -Wno-uninitialized -DNO_FPRINTF_OUTPUT -pipe -c -O3 -o bin/cmdstan/stanc.o src/cmdstan/stanc.cpp
g++: error: unrecognized command line option ‘-stdlib=libc++’
make: *** [bin/cmdstan/stanc.o] Error 1

or
$ make foo/bar
clang++ -Wall -I . -isystem stan/lib/stan_math/lib/eigen_3.3.3 -isystem stan/lib/stan_math/lib/boost_1.64.0 -isystem stan/lib/stan_math/lib/cvodes_2.9.0/include -std=c++1y -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I src -I stan/src -isystem stan/lib/stan_math/ -DEIGEN_NO_DEBUG -DFUSION_MAX_VECTOR_SIZE=12 -stdlib=libc++ -Wno-unused-function -Wno-uninitialized -DNO_FPRINTF_OUTPUT -pipe -c -O3 -o bin/cmdstan/stanc.o src/cmdstan/stanc.cpp
make: clang++: Command not found
make: *** [bin/cmdstan/stanc.o] Error 127

In summary, there is no way for me to make it work.


#5

Can you try commenting out that same line for your clang++ build? That looks like the same problem.


#6

@bbbales2 thanks though I don’t understand what you were asking.

Anyways! It turns out I need to install a package called libc++-dev for building it with clang++. Is there an instruction for linux users to get the essentials for building cmdstan? And I don’t understand installing rstan went ok (rstan is not using libc++?)

[edit: escaped package names]


#7

IIRC rstan uses separate makefiles whereas CmdStan is pulling in the stan-dev/math makefile detect_cc which is causing this problem.