4

sir,

I have two contracts. I want to test the import statement in geth. My first contract is names strtest.sol. The code is below:

pragma solidity ^0.4.2;
import "global_functions.sol";
contract strtest
{
    bool ib_equal;
    function test(string p1,string p2) returns(bool) {
        ib_equal = strcompare(p1,p2) ;
        return true;
    }
}

Another contract is named "global_functions.sol". The code is below:

function strcompare(string p_source,string p_target) external returns(bool) {
    bytes memory lbt_left;
    bytes memory lbt_right;            
    lbt_left = bytes(p_source);
    lbt_right = bytes(p_target);
    bool lb_equal = true;
    uint li_length = lbt_right.length;
    for( uint p = 0 ;p < li_length;p++){
        if (lbt_left[p] == lbt_right[p] ) {
            continue;
        } else {
            lb_equal = false;
            break;
        }
    }
    return lb_equal;
}

My question is: How to compiler strtest in geth? ( Not in Browser-Solidity)

Below is my test situation:

> var test1 = "pragma solidity ^0.4.2;import '/barkely/lend/global_functions.sol';contract strtest { bool ib_equal; function test(string p1,string p2) returns(bool) { return true;  }}"
undefined
> var test1Compiled = web3.eth.compile.solidity(test1)

Error: solc: exit status 1
/tmp/geth-compile-solidity119170518:1:24: Error: Source "/barkely/lend/global_functions.sol" not found: File not found.
pragma solidity ^0.4.2;import '/barkely/lend/global_functions.sol';contract strtest { bool ib_equal; function test(string p1,string p2) returns(bool) { return true;  }}
                       ^------------------------------------------^

    at web3.js:3119:20
    at web3.js:6023:15
    at web3.js:4995:36
    at <anonymous>:1:21

> 

Now, How I change the import path,ex:

import '/barkely/lend/global_functions.sol'  //absoulte path

or

import './global_functions.sol'  //the same path with strtest.sol

,it doesn't work.

So how should I do?

Thanks! Barkely

2

use the second option it is easiest

import "./global_functions.sol" //the file should be in the current directory

where . represents the current and .. as the parent directory. please read more to understand how to import a file in the official doc.

2

sir,

I use the second option,it doesn't work. The error message is below:

Error: solc: exit status 1
/tmp/geth-compile-solidity546755989:1:24: Error: Source "/tmp/str2.sol" not found: File not found.

So I copy the str2.sol to /tmp/str2.sol,then this program works. Client program can call the "test" function of "strtest" contract and the result is correct.

I will try it till find the solution. Any new result ,I will post to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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