無法在 Mac OS X 上安裝 solc
我無法在 Mac OS X 上安裝 solc。我嘗試了以下方法:
npm install solc /Users/punddalinni └── solc@0.3.0-1 npm WARN enoent ENOENT: no such file or directory, open '/Users/punddalinni/package.json' npm WARN punddalinni No description npm WARN punddalinni No repository field. npm WARN punddalinni No README data npm WARN punddalinni No license field.
當我回到geth,我跑了
> eth.getCompilers() [""]
當我嘗試 setSolc 時,發生了以下情況
> admin.setSolc('/Users/punddalinni/node_modules/solc') exec: "/Users/punddalinni/node_modules/solc": permission denied at InvalidResponse (<anonymous>:-81662:-57) at send (<anonymous>:-156322:-57) at setSolc (<anonymous>:-133322:-57) at <anonymous>:1:1
我試過按照這裡的指示,但它卡在
brew install llvm --HEAD --with-clang
編輯:在 Mac 中包括來自 solc 的 package.json 的內容。
{ "_args": [ [ "solc", "/Users/punddalinni" ] ], "_from": "solc@latest", "_id": "solc@0.3.0-1", "_inCache": true, "_installable": true, "_location": "/solc", "_nodeVersion": "4.0.0", "_npmOperationalInternal": { "host": "packages-13-west.internal.npmjs.com", "tmp": "tmp/solc-0.3.0-1.tgz_1457892692634_0.5487515390850604" }, "_npmUser": { "email": "d11e9@turkd.net", "name": "d11e9" }, "_npmVersion": "3.3.2", "_phantomChildren": {}, "_requested": { "name": "solc", "raw": "solc", "rawSpec": "", "scope": null, "spec": "latest", "type": "tag" }, "_requiredBy": [ "#USER" ], "_resolved": "https://registry.npmjs.org/solc/-/solc-0.3.0-1.tgz", "_shasum": "523e79db0c69070f91fcbf408e8c7d0c93be176c", "_shrinkwrap": null, "_spec": "solc", "_where": "/Users/punddalinni", "author": { "name": "chriseth" }, "bugs": { "url": "https://github.com/chriseth/browser-solidity/issues" }, "dependencies": {}, "description": "Solidity compiler", "devDependencies": {}, "directories": {}, "dist": { "shasum": "523e79db0c69070f91fcbf408e8c7d0c93be176c", "tarball": "http://registry.npmjs.org/solc/-/solc-0.3.0-1.tgz" }, "gitHead": "5ce686c8d33db78c8f1eb8e2318eefbc5151f0eb", "homepage": "https://github.com/chriseth/browser-solidity#readme", "keywords": [ "compiler", "ethereum", "solidity" ], "license": "MIT", "main": "index.js", "maintainers": [ { "name": "chriseth", "email": "c@ethdev.com" }, { "name": "d11e9", "email": "d11e9@turkd.net" } ], "name": "solc", "optionalDependencies": {}, "readme": "ERROR: No README data found!", "repository": { "type": "git", "url": "git+https://github.com/chriseth/browser-solidity.git" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "version": "0.3.0-1" }
有任何想法嗎?
我不熟悉 NPM,所以有一些類似的問題。簡單地執行
npm install solc
將嘗試在本地安裝,這可能會出現一些權限和連結問題——這可能是問題的原因。相反,請使用全域安裝 solC
$ npm install -g solc
(您可能還想嘗試$ npm install solc --global
,因為我不確定這兩個命令中的哪一個解決了我的問題)。如果已安裝,請通過執行檢查它的安裝位置,
$ which solcjs
這應該會產生類似/usr/local/bin/solcjs
我發現我還需要按照安裝說明使用 Homebrew 來安裝/建構 solC。Brew 完成後,我檢查了 solC 是否安裝了
$ which sol
.複製此目錄,然後在啟動
geth console
後在 setSolc 命令中使用它,例如> admin.setSolc("/usr/local/bin/solc")
運氣好的話,您會收到一條確認消息,下次執行時
> eth.getCompilers()
,結果應該類似於["Solidity"]
啊……你用錯了。Web3 教程沒有反映這一點,但是在使用從原始碼編譯器建構的(這是 web3 假設的)和 npm 包(教程不圍繞它)設置 Solidity 以在 web3 上編譯的方式之間存在差異. 為了編譯,您需要按照 Browser-solidity 頁面的說明進行操作:
https://github.com/chriseth/browser-solidity
摘抄:
var solc = require('solc'); var input = "contract x { function g() {} }"; var output = solc.compile(input, 1); // 1 activates the optimiser for (var contractName in output.contracts) { // code and ABI that are needed by web3 console.log(contractName + ': ' + output.contracts[contractName].bytecode); console.log(contractName + '; ' + JSON.parse( output.contracts[contractName].interface)); }