Error when compiling C++ code that includes JlCxx

I am trying to learn enough C++ so I can leverage the arrow library to write a ParquetWriter.

I can compile arrow and I can compile JlCxx, and by following the guides in arrow I can build an application that #include <arrow> and I can build an executable by following the guide in JlCxx.

So the next step is to compile an app with both libraries included. But I seem to have issues with JlCxx code.

I am quite new to C++ so the question probably sounds stupid, but I am the only person giving it some serious time to get a Parquet writer in Julia up and running, so your help would benefit the community if I succeed. Any help will be much appreciated including things like “u don’t have enough background knowledge go read XYZ”.

Here is the issue, I have a test.cpp file

#include "jlcxx/jlcxx.hpp"
#include <julia.h>

JULIA_DEFINE_FAST_TLS() // only define this once, in an executable (not in a shared library) if you want fast code.

int main(int argc, char *argv[])
{
    /* required: setup the Julia context */
    jl_init();

    /* run Julia commands */
    jl_eval_string("print(sqrt(2.0))");

    /* strongly recommended: notify Julia that the
         program is about to terminate. this allows
         Julia time to cleanup pending write requests
         and run all finalizers
    */
    jl_atexit_hook(0);
    return 0;
}

I am on Ubuntu 18.04 and Julia 1.4.1.
So I try to compile it using

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/xiaodai/git/arrow_install_path/lib:/home/xiaodai/julia-1.4.1/lib

g++ test.cpp \
    -I/home/xiaodai/git/arrow_install_path/include \
    -I/home/xiaodai/julia-1.4.1/include/julia \
    -I/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include \
    -L/home/xiaodai/git/arrow_install_path/lib \
    -L/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/lib \
    -L/home/xiaodai/julia-1.4.1/lib \
    -lparquet -larrow  -ljulia /home/xiaodai/julia-1.4.1/lib/julia/libstdc++.so.6 \
    -ljlcxx \
    -o test

But I get the below error, which seems to suggest there is some syntax error. Any tip on how to set this up so that I can compile this simple file successfully would be much appreciated!

In file included from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp:4:0,
                 from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/jlcxx.hpp:13,
                 from test.cpp:1:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/type_conversion.hpp:204:43: error: expected template-name before ‘<’ token
 struct IsMirroredType : std::bool_constant<(!std::is_class<T>::value || (std::is_standard_layout<T>::value && std::is_trivial<T>::value)) && !IsSmartPointerType<T>::value>
                                           ^
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/type_conversion.hpp:204:43: error: expected ‘{’ before ‘<’ token
In file included from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp:5:0,
                 from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/jlcxx.hpp:13,
                 from test.cpp:1:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/tuple.hpp: In static member function ‘static jl_datatype_t* jlcxx::julia_type_factory<std::tuple<_Tps ...>, jlcxx::TupleTrait>::julia_type()’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/tuple.hpp:85:38: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
     (create_if_not_exists<TypesT>(), ...);
                                      ^~~
In file included from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/jlcxx.hpp:13:0,
                 from test.cpp:1:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp: In member function ‘ValueT& jlcxx::ArrayRef<ValueT, Dim>::operator[](std::size_t)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp:220:8: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
     if constexpr(std::is_same<julia_t, ValueT>::value)
        ^~~~~~~~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp: In member function ‘const ValueT& jlcxx::ArrayRef<ValueT, Dim>::operator[](std::size_t) const’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/array.hpp:232:8: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
     if constexpr(std::is_same<julia_t, ValueT>::value)
        ^~~~~~~~~
In file included from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/jlcxx.hpp:14:0,
                 from test.cpp:1:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In constructor ‘jlcxx::FunctionWrapper<R, Args>::FunctionWrapper(jlcxx::Module*, const functor_t&)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:198:36: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
     (create_if_not_exists<Args>(), ...);
                                    ^~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In constructor ‘jlcxx::FunctionPtrWrapper<R, Args>::FunctionPtrWrapper(jlcxx::Module*, R (*)(Args ...))’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:230:36: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
     (create_if_not_exists<Args>(), ...);
                                    ^~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In member function ‘void jlcxx::detail::ForEachParameterType<F, jlcxx::ParameterList<ParametersT ...> >::operator()(F&&)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:371:40: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
       (f.template apply<ParametersT>(),...);
                                        ^~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: At global scope:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:494:49: error: expected template-name before ‘<’ token
 struct DefaultConstructible : std::bool_constant<std::is_default_constructible<T>::value && !std::is_abstract<T>::value>
                                                 ^
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:494:49: error: expected ‘{’ before ‘<’ token
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:500:46: error: expected template-name before ‘<’ token
 struct CopyConstructible : std::bool_constant<std::is_copy_constructible<T>::value && !std::is_abstract<T>::value>
                                              ^
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:500:46: error: expected ‘{’ before ‘<’ token
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In member function ‘void jlcxx::Module::add_copy_constructor(jl_datatype_t*)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:669:8: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
     if constexpr (CopyConstructible<T>::value)
        ^~~~~~~~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In member function ‘void jlcxx::Module::add_default_constructor(jl_datatype_t*)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:706:6: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
   if constexpr (DefaultConstructible<T>::value)
      ^~~~~~~~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In function ‘void jlcxx::detail::create_parameter_types(jlcxx::ParameterList<ParametersT ...>, std::index_sequence<Indices ...>)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:924:55: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
     (create_parameter_type<N, ParametersT,Indices>(), ...);
                                                       ^~~
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp: In member function ‘jlcxx::TypeWrapper<T>& jlcxx::TypeWrapper<T>::constructor(bool)’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/module.hpp:967:8: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
     if constexpr (!(DefaultConstructible<T>::value && sizeof...(ArgsT) == 0))
        ^~~~~~~~~
In file included from /home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/jlcxx.hpp:15:0,
                 from test.cpp:1:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/smart_pointers.hpp: In static member function ‘static jl_datatype_t* jlcxx::julia_type_factory<T, jlcxx::CxxWrappedTrait<jlcxx::SmartPointerTrait> >::julia_type()’:
/home/xiaodai/.julia/artifacts/b55cd96f4dd60da926644fc18aef04c69f891b7d/include/jlcxx/smart_pointers.hpp:210:8: warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
     if constexpr(!std::is_same<supertype<PointeeT>, PointeeT>::value)
        ^~~~~~~~~

The -std=c++1z makes the compiler use experimental support for the c++ 17 standard. You seem to be building it with an earlier version of the standard, probably c++14 or c++ 11. Add that flag in and see if that fixes things. You may need to upgrade to a newer version of the compiler.

1 Like

Hey it’s working already!!