mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.94k stars 716 forks source link

building on macOS #974

Closed nhooyr closed 7 years ago

nhooyr commented 7 years ago

When trying to build with clang++, I get the following error:

/p/t/k/src
❯ make CXX=clang++                                                                                                                                                                                         i
clang++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -stdlib=libc++ -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .color.debug.d -c -o .color.debug.o color.cc
In file included from color.cc:1:
In file included from ./color.hh:4:
./hash.hh:4:10: fatal error: 'type_traits' file not found
#include <type_traits>
         ^
1 error generated.
make: *** [.color.debug.o] Error 1

my clang++ version is

clang version 3.7.1 (tags/RELEASE_371/final)
Target: x86_64-apple-darwin16.1.0
Thread model: posix

Any ideas what is wrong?

nhooyr commented 7 years ago

If I use the clang++ that is included in macOS (I was using clang++ from my package manager nix above), I get

/p/t/k/src
❯ make CXX=clang++                                                                                  i
clang++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -stdlib=libc++ -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .color.debug.d -c -o .color.debug.o color.cc
In file included from color.cc:1:
In file included from ./color.hh:4:
./hash.hh:14:18: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<typename... Type>
                 ^
./hash.hh:29:24: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
size_t hash_values(Type&& t)
                       ^
./hash.hh:39:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<typename Type, typename... RemainingTypes>
                                ^
./hash.hh:40:24: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
size_t hash_values(Type&& t, RemainingTypes&&... rt)
                       ^
./hash.hh:40:44: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
size_t hash_values(Type&& t, RemainingTypes&&... rt)
                                           ^
In file included from color.cc:1:
./color.hh:14:10: error: ISO C++ forbids forward references to 'enum' types
    enum NamedColor : char
         ^
./color.hh:15:5: error: expected '(' for function-style cast or type construction
    {
    ^
./color.hh:14:21: error: field has incomplete type 'enum NamedColor'
    enum NamedColor : char
                    ^
./color.hh:14:10: note: forward declaration of 'Kakoune::NamedColor'
    enum NamedColor : char
         ^
./color.hh:28:16: error: field has incomplete type 'Kakoune::NamedColor'
    NamedColor color;
               ^
./color.hh:14:10: note: forward declaration of 'Kakoune::NamedColor'
    enum NamedColor : char
         ^
./color.hh:29:21: warning: in-class initialization of non-static data member is a C++11 extension
      [-Wc++11-extensions]
    unsigned char r = 0;
                    ^
./color.hh:30:21: warning: in-class initialization of non-static data member is a C++11 extension
      [-Wc++11-extensions]
    unsigned char g = 0;
                    ^
./color.hh:31:21: warning: in-class initialization of non-static data member is a C++11 extension
      [-Wc++11-extensions]
    unsigned char b = 0;
                    ^
./color.hh:33:5: error: unknown type name 'constexpr'
    constexpr Color() : Color{Default} {}
    ^
./color.hh:33:15: error: constructor cannot have a return type
    constexpr Color() : Color{Default} {}
              ^~~~~
./color.hh:33:40: error: expected member name or ';' after declaration specifiers
    constexpr Color() : Color{Default} {}
                                       ^
./color.hh:39:1: error: unknown type name 'constexpr'
constexpr bool operator==(Color lhs, Color rhs)
^
./color.hh:39:11: error: expected unqualified-id
constexpr bool operator==(Color lhs, Color rhs)
          ^
./color.hh:45:1: error: unknown type name 'constexpr'
constexpr bool operator!=(Color lhs, Color rhs)
^
./color.hh:45:11: error: expected unqualified-id
constexpr bool operator!=(Color lhs, Color rhs)
          ^
./color.hh:60:32: error: no member named 'RGB' in 'Kakoune::Color'
    return val.color == Color::RGB ?
                        ~~~~~~~^
In file included from color.cc:3:
./containers.hh:15:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto operator| (Container&& container, ContainerView<Factory> view) ->
^
./containers.hh:15:26: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
auto operator| (Container&& container, ContainerView<Factory> view) ->
                         ^
./containers.hh:15:1: error: 'auto' not allowed in function return type
auto operator| (Container&& container, ContainerView<Factory> view) ->
^~~~
./containers.hh:15:68: error: expected ';' at end of declaration
auto operator| (Container&& container, ContainerView<Factory> view) ->
                                                                   ^
                                                                   ;
./containers.hh:15:69: error: cannot use arrow operator on a type
auto operator| (Container&& container, ContainerView<Factory> view) ->
                                                                    ^
./containers.hh:24:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using iterator = decltype(std::declval<Container>().rbegin());
                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:605:25: note:
      expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                        ^
In file included from color.cc:3:
./containers.hh:33:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using RemoveReference = typename std::remove_reference<C>::type;
                        ^
./containers.hh:38:42: error: a space is required between consecutive right angle brackets
      (use '> >')
    ReverseView<RemoveReference<Container>> operator()(Container&& container) const
                                         ^~
                                         > >
./containers.hh:38:65: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    ReverseView<RemoveReference<Container>> operator()(Container&& container) const
                                                                ^
./containers.hh:40:16: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
        return {std::move(container)};
               ^~~~~~~~~~~~~~~~~~~~~~
./containers.hh:46:16: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
        return {container};
               ^~~~~~~~~~~
./containers.hh:50:57: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
inline ContainerView<ReverseFactory> reverse() { return {}; }
                                                        ^~
./containers.hh:53:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using IteratorOf = decltype(std::begin(std::declval<Container>()));
                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:605:25: note:
      expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                        ^
In file included from color.cc:3:
./containers.hh:56:17: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using ValueOf = typename Container::value_type;
                ^
./containers.hh:61:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using ContainerIt = IteratorOf<Container>;
                        ^
./containers.hh:67:34: error: expected member name or ';' after declaration specifiers
            : m_it{std::move(it)}, m_end{std::move(end)}, m_view{view}
                                 ^
./containers.hh:67:19: error: expected '('
            : m_it{std::move(it)}, m_end{std::move(end)}, m_view{view}
                  ^
./containers.hh:67:33: error: expected ';' after expression
            : m_it{std::move(it)}, m_end{std::move(end)}, m_view{view}
                                ^
                                ;
./containers.hh:100:37: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
    Iterator begin() const { return {*this, std::begin(m_container), std::end(m_container)}; }
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./containers.hh:101:37: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
    Iterator end()   const { return {*this, std::end(m_container), std::end(m_container)}; }
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./containers.hh:114:72: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    FilterView<RemoveReference<Container>, Filter> operator()(Container&& container) const { ...
                                                                       ^
./containers.hh:111:84: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
  ...Filter> operator()(Container& container) const { return {container, std::move(m_filter)}; }
                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./containers.hh:114:101: warning: generalized initializer lists are a C++11 extension
      [-Wc++11-extensions]
  ...container) const { return {std::move(container), std::move(m_filter)}; }
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
24 warnings and 20 errors generated.
make: *** [.color.debug.o] Error 1
lenormf commented 7 years ago

In the second case you can add the -Wc++11-extensions flag to CXXFLAGS in the Makefile.

nhooyr commented 7 years ago

Actually, with the system clang++, I get

clang++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .color.debug.d -c -o .color.debug.o color.cc
In file included from color.cc:4:
In file included from ./exception.hh:4:
./string.hh:96:3: warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
[[gnu::optimize(3)]] // this is recursive for constexpr reason
  ^
In file included from color.cc:5:
./regex.hh:8:10: fatal error: 'boost/regex.hpp' file not found
#include <boost/regex.hpp>
         ^
1 warning and 1 error generated.
make: *** [.color.debug.o] Error 1

I can't seem to reproduce the output I got in my second comment. weird.

lilyball commented 7 years ago

Looks like it can't find boost. Perhaps you need -I/usr/local/include (or -I/usr/local/opt/boost/include).

mawww commented 7 years ago

The initial error would suggest that libc++ is not actually installed, is -stdlib=libc++ needed on OSX ?

lilyball commented 7 years ago

If you have Apple's developer tools installed (which is where system clang++ comes from), then you have libc++. And I think libc++ is now the default, though I'm not sure offhand how to actually check.

cvlmtg commented 7 years ago

Hi, I tried installing it today and this is what I get:

==> make install PREFIX=/usr/local/Cellar/kakoune/HEAD-4f98677
Last 15 lines from /Users/matteo/Library/Logs/Homebrew/kakoune/01.make:
In file included from ./scope.hh:7:
./option_manager.hh:143:24: error: cannot pass object of non-trivial type 'Kakoune::Regex' through variadic function; call will abort at runtime [-Wnon-pod-varargs]
        if (option_add(m_value, str))
                       ^
./option_manager.hh:166:27: note: in instantiation of member function 'Kakoune::TypedOption<Kakoune::Regex>::add_from_string' requested here
    using TypedOption<T>::TypedOption;
                          ^
commands.cc:1335:24: note: in instantiation of function template specialization 'Kakoune::OptionsRegistry::declare_option<Kakoune::Regex, nullptr>' requested here
            opt = &reg.declare_option<Regex>(parser[1], docstring, Regex{}, flags);
                       ^
clang++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .highlighters.debug.d -c -o .highlighters.debug.o highlighters.cc
clang++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .hook_manager.debug.d -c -o .hook_manager.debug.o hook_manager.cc
1 error generated.
make: *** [.commands.debug.o] Error 1
make: *** Waiting for unfinished jobs....

this is on macos sierra using brew install --HEAD https://raw.githubusercontent.com/mawww/kakoune/master/contrib/kakoune.rb

wmcg commented 7 years ago

I am also getting that error and i raised a (possibly duplicate) issue here https://github.com/mawww/kakoune/issues/1090

casimir commented 7 years ago

@cvlmtg @wmcg this is not the same error, #1090 is the place to go.

@nhooyr any luck on building with newer commits?

nhooyr commented 7 years ago

@casimir I get

/p/t/k/src
❯ make                                                                         i
c++ -DKAK_DEBUG -I/usr/local/opt/ncurses/include -pedantic -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -Wno-address -MD -MP -MF .color.debug.d -c -o .color.debug.o color.cc
In file included from color.cc:4:
In file included from ./exception.hh:4:
./string.hh:96:3: warning: unknown attribute 'optimize' ignored
      [-Wunknown-attributes]
[[gnu::optimize(3)]] // this is recursive for constexpr reason
  ^
In file included from color.cc:5:
./regex.hh:8:10: fatal error: 'boost/regex.hpp' file not found
#include <boost/regex.hpp>
         ^
1 warning and 1 error generated.
make: *** [.color.debug.o] Error 1
casimir commented 7 years ago

@kballard had the first part of the answer, just like ncurses boost need to be in {LD,CPP}FLAGS when built manually.

nhooyr commented 7 years ago

I got it to build with make -stdlib=libc++ as suggested by @mawww , I tried that before but it didn't work. Now it's working fine.

However, the executable is not produced, it is just a zero length file named kak. The output is https://gist.githubusercontent.com/nhooyr/894f1fe684914a8633d56f16595e056a/raw/f07dc3f5563550f30c77531869ac8c352a874605/gistfile1.txt

nhooyr commented 7 years ago

Pretty sure this was me not understanding how to correctly use nix.

I've switched to homebrew and it's all working fine.

edjroot commented 7 years ago

Sorry, I'm having exactly the same issue on Bash on Ubuntu on Windows. Each step followed caused a new problem, just as shown in the comments. Only make -stdlib=libc++ causes no errors, but the generated kak file is empty. What can I do to get it running?

Thanks in advance!

mawww commented 7 years ago

@edjroot not sure what make -stdlib=libc++ will do, the correct command would be CXXFLAGS="-stdlib=libc++" make

edjroot commented 7 years ago

@mawww, oops, I'm new to this thing and was just following previous comments.

I just tried CXXFLAGS="-stdlib=libc++" make and now I'm getting "g++: error: unrecognized command line option ‘-stdlib=libc++’". I'm afraid I messed something up while trying to get this working.

mawww commented 7 years ago

Yeah, -stdlib=libc++ is a clang specific option, to compile with clang using libc++, you need the full CXX=clang++ CXXFLAGS="-stdlib=libc++" make command.

edjroot commented 7 years ago

Duh, sorry.

I still got other errors after I tried that, so I just reinstalled WSL and successfully installed Kakoune on the first try.

Thanks for the help!