9

Geth console outputs after admin.setSolc("/usr/bin/solc"):

eth.compile.solidity("")
I0601 15:31:56.663260 common/compiler/solidity.go:114] solc, the solidity compiler commandline interface
Version: 0.3.3-0/RelWithDebInfo-Linux/g++/Interpreter
path: /usr/bin/solc
solc: empty source string
at web3.js:3119:20
at web3.js:6023:15
at web3.js:4995:36
at :1:1

and

eth.getCompilers()
[]

I am getting an empty array instead of ['Solidity'].

Installed solidity through: sudo apt-get install solc

output for which solc: /usr/bin/solc (added this to PATH)

I have seen a similar question, but I am using the latest version (0.3.3) and still have the problem. Am I missing anything?

1 Answer 1

5

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.

6
  • Thank you @BokkyPooBah. The compiler was working fine. I just wanted to know whether eth,getCompilers() result was different only for me.
    – galahad
    Commented Jun 9, 2016 at 15:18
  • No worries. There was a segmentation fault problem with solc in another question, so I was curious enough to check your question out. Commented Jun 9, 2016 at 15:21
  • I'm running into the same issue as @varm. solc compiles your code snippet just fine on the cli (I'm getting the same binary string back), but as soon as I load up geth and try to compile via eth.compile.solidity, I get solc: exit status 1; Unknown exception during compilation. When you say the empty getCompilers result is normal, what does that mean exactly? What makes this function return something or not?
    – mxk
    Commented Jun 14, 2016 at 15:02
  • @Matthias, I've added some further information to help you try to solve your solc issue. Some possibilities: solc cannot create the temp subdirectory; solc cannot compile correctly with some of the command line parameters --bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc067035811. Commented Jun 14, 2016 at 15:30
  • Thanks @BokkyPooBah -- I ran it with all these switches, and it works fine on the command line. I'm seeing all the same output and files created. Yet, I still cannot execute the compiler from within geth.
    – mxk
    Commented Jun 14, 2016 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.