Summary
Segmentation fault with solc version 0.3.2-7a51852a/Release-Darwin/appleclang/JIT , fixed with later updated version.
UPDATE 26/06/2016
This is a bug in the Solidity compiler.
Here is a quick test:
user@Kumquat:~$ echo '' | solc
Unknown exception during compilation.
See eth.compile.solidity
fails with solc version 0.3.5 #2703, which links to Exception on compilation from stdin #651.
And the issue Fix crash for input from stdin. #652 has been fixed, but will take an unknown (hopefully short) amount of time to make it into the repository packages.
This is the code change for the fix - Fix crash for input from stdin. #652 - Files changed.
You can try installing the previous version of solc
.
Or one workaround offered in the first link above:
For anyone who wants a temporary workaround, you can clone this repo: https://github.com/mattdf/solidity-static and do a build in docker, then copy the solc file to your install. It makes a statically compiled build of solc so it should work on most distros.
Details
Check Solidity Compiler Within geth
I just checked by installation (Linux) and the output that you are getting is consistent with the output I get, but the compiler works correctly.
Run the test below to check if your compiler is configured correctly.
I'm using the following code:
contract Test {
function double(int a) constant returns(int) {
return 2*a;
}
}
I've flattened the code above to:
> var testSource='contract Test { function double(int a) constant returns(int) { return 2*a; } }'
undefined
I've tried compiling the code using the following statement:
> var testCompiled = web3.eth.compile.solidity(testSource);
undefined
And checked the results of the compilation:
> testCompiled
{
Test: {
code: "0x6060604052602a8060106000396000f3606060405260e060020a60003504636ffa1caa8114601a575b005b6002600435026060908152602090f3",
info: {
abiDefinition: [{...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc935251869",
compilerVersion: "0.3.2",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.2",
source: "contract Test { function double(int a) constant returns(int) { return 2*a; } }",
userDoc: {
methods: {}
}
}
}
}
And if you want to check if the code runs correctly:
> var testContract = web3.eth.contract(testCompiled.Test.info.abiDefinition);
var test = testContract.new({
from:web3.eth.accounts[0],
data: testCompiled.Test.code, gas: 2000000},
function(e, contract) {
if (!e) {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
})
...
Contract mined! Address: 0x5e3361efa79827d8a53a397b454770c6816585d7
> test.double(5)
10
Check Solidity Compiler
If you are still encountering problems, let's try compiling the source code outside geth
.
Save the following code into Test.sol:
contract Test {
function double(int a) constant returns(int) {
return 2*a;
}
}
From your terminal, you should be able to run the following commands if your solidity compiler is working correctly:
user@Kumquat:~$ solc --bin Test.sol
======= Test =======
Binary:
606060405260728060106000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480636ffa1caa146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000816002029050606d565b91905056
user@Kumquat:~$ solc --abi Test.sol
======= Test =======
Contract JSON ABI
[{"constant":true,"inputs": [{"name":"a","type":"int256"}],"name":"double","outputs":[{"name":"","type":"int256"}],"type":"function"}]
If the commands above do not produce similar output, there is something not quite right with your solc
binary.
Check web3.js
You have an error message that includes the text web3.js
. The problem could be with this module. I'll update when I've researched it a bit more.
Best Answer
I'm working through this same course check this out and it will show you how to fix this error here: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/blob/main/chronological-issues-from-video.md
You just need to do the following: On the line that says
We need to change it to this line:
And then, we need to add a line right before we run the
compile_standard
code:Alternatively, you can install Solc first before installing solcx and it will give you the old version of solidity compiler included. so all you have to do is import from solcx.
Also I noticed in your settings array here:
you used curly braces instead of square brackets so you will need to fix that before you try to compile. It needs to look like this