The empty eth.getCompilers()
result is normal.
You can try the below:
> eth.getCompilers()
[]
> var ceilSource='contract Ceil { function ceil(uint a, uint m) constant returns (uint ) { return ((a + m - 1) / m) * m; }}'
undefined
> var ceilCompiled = web3.eth.compile.solidity(ceilSource);
undefined
> ceilCompiled
{
Ceil: {
code: "0x606060405260348060106000396000f3606060405260e060020a60003504638587be6e8114601a575b005b602435600435810160001901819004026060908152602090f3",
info: {
abiDefinition: [{...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc067035811",
compilerVersion: "0.3.4",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.4",
source: "contract Ceil { function ceil(uint a, uint m) constant returns (uint ) { return ((a + m - 1) / m) * m; }}",
userDoc: {
methods: {}
}
}
}
}
If you can reproduce the results above, your compiler installation is working correctly.
(The code is from What is the cheapest way to roundup() or ceil() to multiple of 1000?).
Also, I'm getting the same results are you are when compiling an empty string:
> eth.compile.solidity("")
solc: empty source string
at web3.js:3119:20
at web3.js:6023:15
at web3.js:4995:36
at <anonymous>:1:1
EDIT 15/06/2016 - Responding to @Matthias
Q: When you say the empty getCompilers result is normal, what does that mean exactly? What makes this function return something or not?
A: I don't know what the []
result from eth.getCompilers()
exactly means, but when I run the following commands on my geth console
screen, the results returned are what I see, and I have no problems compiling Solidity code from within geth
. I'm just trying to eliminate the different points of error.
Here is what I see:
geth console
...
> eth.getCompilers()
I0615 01:17:48.956307 common/compiler/solidity.go:114] solc, the solidity compiler commandline interface
Version: 0.3.4-0/RelWithDebInfo-Linux/g++/Interpreter
path: /usr/bin/solc
[]
> eth.getCompilers()
[]
The first run of getCompilers()
produces some results from solc
. From the command line, if I run solc --version
I get the version information as well.
user@Kumquat:~/TestSolc$ solc --version
solc, the solidity compiler commandline interface
Version: 0.3.4-0/RelWithDebInfo-Linux/g++/Interpreter
If you can see similar information to what I am getting, you Solidity compiler is accessible from geth
.
Here is one extra test you can try if you have a problem compiling Solidity source from within geth
.
I've saved the following code into Ceil.sol:
contract Ceil {
function ceil(uint a, uint m) constant returns (uint ) {
return ((a + m - 1) / m) * m;
}
// To measure gas
function ceil1(uint a, uint m) returns (uint ) {
return ((a + m - 1) / m) * m;
}
}
I'm now compiling outside geth
using the command line parameters in the ceilCompiled
results above:
user@Kumquat:~/TestSolc$ solc --bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc067035811 Ceil.sol
Here is the contents of my /tmp/solc067035811 directory:
user@Kumquat:~/TestSolc$ ls -al /tmp/solc067035811/
total 24
drwxrwxr-x 2 bok bok 4096 Jun 15 01:21 .
drwxrwxrwt 12 root root 4096 Jun 15 01:22 ..
-rw-rw-r-- 1 bok bok 328 Jun 15 01:21 Ceil.abi
-rw-rw-r-- 1 bok bok 156 Jun 15 01:21 Ceil.bin
-rw-rw-r-- 1 bok bok 22 Jun 15 01:21 Ceil.docdev
-rw-rw-r-- 1 bok bok 22 Jun 15 01:21 Ceil.docuser
And here is the content of the files in the /tmp/solc067035811 directory:
user@Kumquat:~/TestSolc$ cat /tmp/solc067035811/Ceil.abi
[{"constant":false,"inputs":[{"name":"a","type":"uint256"},
{"name":"m","type":"uint256"}],"name":"ceil1","outputs":
[{"name":"","type":"uint256"}],"type":"function"},
{"constant":true,"inputs":[{"name":"a","type":"uint256"},
{"name":"m","type":"uint256"}],"name":"ceil","outputs":
[{"name":"","type":"uint256"}],"type":"function"}]
user@Kumquat:~/TestSolc$ cat /tmp/solc067035811/Ceil.bin
6060604052603e8060106000396000f3606060405260e060020a600035046314bdae22811460245780638587be6e146024575b005b602435600435810160001901819004026060908152602090f3 user@Kumquat:~/TestSolc$ cat /tmp/solc067035811/Ceil.docdev
{
"methods" : {}
}
user@Kumquat:~/TestSolc$ cat /tmp/solc067035811/Ceil.docuser
{
"methods" : {}
}
If you can reproduce similar results running solc
from your command line, the problem is most likely not in your Solidity compiler. You will have to keep searching for the cause.