rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.67k stars 190 forks source link

/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace' #457

Closed ahuigo closed 7 months ago

ahuigo commented 4 years ago

I failed to install therubyracer. My env is:

Mac osx: Catalina 10.15.2
Ruby:  ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
clang version 11.0.3 (clang-1103.0.32.59)

Here is output:

$ sudo gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15 
....
    ERROR: Failed to build gem native extension.
......
To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1
....

$ cat /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/mkmf.log
--------------------
find_header: checking for v8.h... -------------------- no

"xcrun clang -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8@3.15/include -I/usr/local/opt/v8@3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wall -g -rdynamic  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from conftest.c:3:
/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace'
namespace v8 {
^
/usr/local/opt/v8@3.15/include/v8.h:98:13: error: expected ';' after top level declarator
namespace v8 {
            ^
            ;
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <v8.h>
/* end */

--------------------
$ gsed -n '95,100p' /usr/local/opt/v8@3.15/include/v8.h
/**
 * The v8 JavaScript engine.
 */
namespace v8 {

class Context;
ahuigo commented 4 years ago

Related issue: https://github.com/rubyjs/therubyracer/issues/455 This error relates the command :

"xcrun clang -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8@3.15/include -I/usr/local/opt/v8@3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wall -g -rdynamic  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from conftest.c:3:
/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace'
gruntfarm commented 4 years ago

Getting the same error and nothing is helping. Tried the method that involves the --with-v8-dir=/usr/local/opt/v8@3.15 flag and I'm still getting the same message.

Also set the following options in my .zshrc file export CXX=clang++ export GYPFLAGS=-Dmac_deployment_target=10.15

gruntfarm commented 4 years ago

Ok fixed it by installing both v8 & theruby racer with bundler and instead of running bundle config build.libv8 --with-system-v8 which is what every instruction here told me, I ran bundle config build.libv8 --with-cxx=clang++

So the full ~/.bundle/config is

---
BUNDLE_BUILD__LIBV8: "--with-cxx=clang++"
BUNDLE_BUILD__THERUBYRACER: "--with-v8-dir=/usr/local/opt/v8@3.15"

You can also maybe add --with-v8-include and --with-v8-lib options to the 2nd line which is what I also had but I don't think those are necessary.

lloeki commented 7 months ago

Sorry but this gem is unmaintained, so I will close this issue.

We recommend going with mini_racer + libv8-node. If you feel the issue is still relevant to either of those, please open an issue over there!