Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed MacOS Catalina node 4.x libstdc++ #61

Closed
saqib-ahmed opened this issue Mar 19, 2020 · 14 comments
Closed

Build failed MacOS Catalina node 4.x libstdc++ #61

saqib-ahmed opened this issue Mar 19, 2020 · 14 comments

Comments

@saqib-ahmed
Copy link

saqib-ahmed commented Mar 19, 2020

My Environment

NodeJS: 4.9.1
NPM: 2.15.11
MacOS Catalina: 10.15.3

The Error

I'm trying to install node-cld and it gives the following error. I'm simply running npm i cld

> node-gyp rebuild

  CXX(target) Release/obj.target/cld/cld/internal/cldutil.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../cld/internal/cldutil.cc:20:
In file included from ../cld/internal/cldutil.h:24:
../cld/internal/cldutil_shared.h:403:8: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
inline const uint32 QuadHashV3Lookup4(const CLD2TableSummary* gram_obj,
       ^~~~~~
../cld/internal/cldutil_shared.h:431:8: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
inline const uint32 OctaHashV3Lookup4(const CLD2TableSummary* gram_obj,
       ^~~~~~
In file included from ../cld/internal/cldutil.cc:20:
In file included from ../cld/internal/cldutil.h:25:
In file included from ../cld/internal/scoreonescriptspan.h:81:
../cld/internal/compact_lang_det_impl.h:22:10: fatal error: 'vector' file not found
#include <vector>
         ^~~~~~~~
3 warnings and 1 error generated.
make: *** [Release/obj.target/cld/cld/internal/cldutil.o] Error 1

It works alright when I try to install it with node v10.x. I need to build it with node v4.9.1. What's wrong here?

@oliverjessner
Copy link

I think most of the libs are dropping support for older node version.
Maybe you find a way to update/migrate your node

@saqib-ahmed
Copy link
Author

Is there any way I can keep my node version and make cld work?
I even tried installing cld@0.0.1 but it didn't work either.

@dachev
Copy link
Owner

dachev commented Mar 19, 2020

Hi @saqib-ahmed, @oliverjessner is right. cld@2.6.0 supports only node 12+. You should be able to build cld@2.5.1 for node 4. Can you try that and if it fails please paste the complete terminal output starting with the npm command and everything after.

@saqib-ahmed
Copy link
Author

Here you go:

npm i cld@2.5.1                                                                                              1 ↵  8.95   17:43:42 
npm WARN engine cld@2.5.1: wanted: {"node":">=12.0.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
/
> cld@2.5.1 install /Users/saqib/dev/SixLogixs/bb-backend/node_modules/cld
> node-gyp rebuild

  CXX(target) Release/obj.target/cld-c/deps/cld/internal/cldutil.o
In file included from ../deps/cld/internal/cldutil.cc:20:
In file included from ../deps/cld/internal/cldutil.h:25:
In file included from ../deps/cld/internal/scoreonescriptspan.h:81:
../deps/cld/internal/compact_lang_det_impl.h:22:10: fatal error: 'vector' file not found
#include <vector>
         ^~~~~~~~
1 error generated.
make: *** [Release/obj.target/cld-c/deps/cld/internal/cldutil.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/saqib/.nvm/versions/node/v4.9.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/Users/saqib/.nvm/versions/node/v4.9.1/bin/node" "/Users/saqib/.nvm/versions/node/v4.9.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/saqib/dev/SixLogixs/bb-backend/node_modules/cld
gyp ERR! node -v v4.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm ERR! Darwin 19.3.0
npm ERR! argv "/Users/saqib/.nvm/versions/node/v4.9.1/bin/node" "/Users/saqib/.nvm/versions/node/v4.9.1/bin/npm" "i" "cld@2.5.1"
npm ERR! node v4.9.1
npm ERR! npm  v2.15.11
npm ERR! code ELIFECYCLE

npm ERR! cld@2.5.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cld@2.5.1 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the cld package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cld
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls cld
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/saqib/dev/SixLogixs/bb-backend/npm-debug.log

=

@saqib-ahmed
Copy link
Author

saqib-ahmed commented Mar 19, 2020

Looks like there's something wrong with my Clang configuration. Doesn't vector come with the standard C++ library?

Here's the output of clang -v:

Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@dachev
Copy link
Owner

dachev commented Mar 19, 2020

It has to be something with Catalina or your particular system. I'll research if there is anything in MacOS 10.15 standard libraries that could be breaking it.

@saqib-ahmed
Copy link
Author

This seems to be a similar issue:
pandas-dev/pandas#23424

@dachev
Copy link
Owner

dachev commented Mar 19, 2020

Does running xcode-select --install help?

@saqib-ahmed
Copy link
Author

Trying. Will update you.

@saqib-ahmed
Copy link
Author

saqib-ahmed commented Mar 19, 2020

@dachev Updating xcode command-line tools didn't help. Any other idea?

@saqib-ahmed
Copy link
Author

The bewildering thing is that node-gyp rebuild works alright for any cld version (tried various including 0.0.1, 2.4.5, 2.5.1 and so on) when I switch to nodejs v10.x. It fails on 4.x but the error is related to a C++ library not found. If the library is the issue, it shouldn't work for any nodejs version. What do you think?

@saqib-ahmed
Copy link
Author

saqib-ahmed commented Mar 19, 2020

After a bit more debugging, tried to see the compiler command that node-gyp runs in case of both the node versions.
v4.9.1: fails with the error posted above

c++ '-DNODE_GYP_MODULE_NAME=cld-c' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' -I/Users/saqib/.node-gyp/4.9.1/include/node -I/Users/saqib/.node-gyp/4.9.1/src -I/Users/saqib/.node-gyp/4.9.1/deps/uv/include -I/Users/saqib/.node-gyp/4.9.1/deps/v8/include -I../deps/cld/internal  -Os -gdwarf-2 -mmacosx-version-min=10.5 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++98 -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -w -MMD -MF ./Release/.deps/Release/obj.target/cld-c/deps/cld/internal/cldutil.o.d.raw   -c -o Release/obj.target/cld-c/deps/cld/internal/cldutil.o ../deps/cld/internal/cldutil.cc

v10.16.3: succeeds

c++ '-DNODE_GYP_MODULE_NAME=cld-c' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' -I/Users/saqib/.node-gyp/10.16.3/include/node -I/Users/saqib/.node-gyp/10.16.3/src -I/Users/saqib/.node-gyp/10.16.3/deps/openssl/config -I/Users/saqib/.node-gyp/10.16.3/deps/openssl/openssl/include -I/Users/saqib/.node-gyp/10.16.3/deps/uv/include -I/Users/saqib/.node-gyp/10.16.3/deps/zlib -I/Users/saqib/.node-gyp/10.16.3/deps/v8/include -I../deps/cld/internal  -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++98 -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -w -MMD -MF ./Release/.deps/Release/obj.target/cld-c/deps/cld/internal/cldutil.o.d.raw   -c -o Release/obj.target/cld-c/deps/cld/internal/cldutil.o ../deps/cld/internal/cldutil.cc

Apart from some extra includes and some other flags I didn't understand, the main difference is -stdlib=libc++ flag. All I need is the cld build with the correct node version, so I'm gonna try and execute the compiler command with libc++ for node_gyp from 4.9.1. Will close the issue once done.

@saqib-ahmed
Copy link
Author

saqib-ahmed commented Mar 19, 2020

Finally, I was able to create a build of node-cld for MacOS Catalina with an older version of nodejs. The problem was really the flag: -stdlib=libc++. macOS Catalina deprecated the use of libstdc++ in favor of libc++. The newer versions of node-gyp do have this change, but older versions do not comply with this, hence the discrepancy. This problem was highlighted apparently in the original error message (first message in this issue):

warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

Just for reference, on an off-chance if anybody needs to build node-cld (or any other nodejs library with native addons for that matter) for nodejs 4.x on MacOS Catalina, you can follow the steps below:

  1. Clone this repository
  2. Checkout to legacy/2.4
  3. Add the following in binding.gyp:
"conditions": [
          [ 'OS=="mac"', {
            "xcode_settings": {
              "OTHER_CPLUSPLUSFLAGS" : [ "-std=c++11", "-stdlib=libc++" ],
              "OTHER_LDFLAGS": [ "-stdlib=libc++" ],
              "MACOSX_DEPLOYMENT_TARGET": "10.7"
            },
          }],
        ]
    }
  ]

OR

  1. You can provide these flags as environment variables:
export CXXFLAGS='-stdlib=libc++ -mmacosx-version-min=10.7'; 
export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.7';

Run npm install and there you have it.

@saqib-ahmed saqib-ahmed changed the title Build failed with error Build failed MacOS Catalina node 4.x libstdc++ Mar 19, 2020
@dachev
Copy link
Owner

dachev commented Mar 20, 2020

Thank you for the research and for sharing your fix @saqib-ahmed. Much appreciated.

@saqib-ahmed saqib-ahmed changed the title Build failed MacOS Catalina node 4.x libstdc++ Build failed MacOS Mojave node 4.x libstdc++ May 8, 2020
@saqib-ahmed saqib-ahmed changed the title Build failed MacOS Mojave node 4.x libstdc++ Build failed MacOS Catalina node 4.x libstdc++ May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants