0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

npm install エラー「npm ERR! g++: error: unrecognized command line option」解決法

Posted at

環境

Mac OS:Monterey 12.0.1
Node.js:16.3.0
npm:7.15.1

エラー内容

npm install した際、以下のようなビルドエラーが発生する。

MacBook-Air:××× $ npm install
(省略)
npm ERR! command failed
npm ERR! command sh -c node ./build.js
npm ERR! make: Entering directory '×××/node_modules/deasync/build'
npm ERR!   CXX(target) Release/obj.target/deasync/src/deasync.o
npm ERR! make: Leaving directory '×××/node_modules/deasync/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@16.3.0 | darwin | x64
npm ERR! gyp info find Python using Python version 3.6.8 found at "/Users/×××/anaconda3/bin/python3"
(省略)
npm ERR! g++: error: unrecognized command line option ‘-std=gnu++14’
npm ERR! g++: error: unrecognized command line option ‘-stdlib=libc++’
(省略)
npm ERR! gyp ERR! node -v v16.3.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok 
npm ERR! Build failed

これらのエラーそのものを調べても、直接の解決方法が出てこなかったため、解決した手順をここに記載する。

解決手順

g++エラー部分を調べると、似たエラーがあり、どうやらgccのバージョンが低いことが原因のようである。

macbook-air:××× $ gcc --version
gcc (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gccを11.2.0_3にアップデートして、バージョンを確認するが、アップデートしたバージョンになっていない。

macbook-air:××× $ brew install gcc

macbook-air:×××$ gcc --version
gcc (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gccを確認すると、anacondaのgccを使ってしまっている。

macbook-air:×××$ which gcc
/×××/anaconda3/bin/gcc

インストールされたgccを確認し、~/.bash_profileに優先されるようにpathを追加する。

macbook-air:××× $ ls /usr/local/bin | grep gcc
gcc-11
gcc-ar-11
gcc-nm-11
gcc-ranlib-11

macbook-air:××× $ vi ~/.bash_profile
macbook-air:××× $ source ~/.bash_profile

gccのバージョンを確認する。

macbook-air:××× $ gcc --version
gcc (Homebrew GCC 11.2.0_3) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

補足・参考情報

gccの環境構築については、こちらの記事がとても参考になります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?