3

The problem involves 3 contracts with an interdependence as follows:
library --> ProductContract --> BillingContract
The contracts are structured as follows: (The DataSet.sol contract below is referenced from a solidity example from: https://github.com/chriseth/solidity-examples/blob/master/iterable_mapping.sol
DataSet.sol:

library DataSet {   
  struct IndexValue { uint keyIndex; uint256 value;}  
  struct KeyFlag { uint key; bool deleted; }  
  struct KeyValue { uint key; uint value; }  

  struct Data {   
      mapping(uint => IndexValue) data;  
      KeyFlag[] keys;  
      //KeyValue[] kvpairs;
      uint size;  
  }  

  function insert(Data storage self, uint key, uint256 value) returns (bool replaced){  
    uint keyIndex = self.data[key].keyIndex;  
    self.data[key].value = value;  
    if (keyIndex > 0)  
      return true;  
    else  
    {  
      keyIndex = self.keys.length++;   
      self.data[key].keyIndex = keyIndex + 1;  
      self.keys[keyIndex].key = key;  
      self.size++;  
      return false;  
    }  
  }  

  function getCurrent(Data storage self) returns(uint index){  
      return self.size - 1;  
  }  

}  

ProductContract.sol:

import "DataSet.sol";  
contract ProductContract {  
    using DataSet for *;  
    DataSet.Data d;  
    mapping (uint => uint) IDToVal;  
    function register (uint p_id, uint val) returns (bool registered) {  
        IDToVal[p_id] = val;  
        registered = true;  
    }  
    function getVal (uint p_id) returns (uint v) {  
         return IDToVal[p_id];  
    }  
}

BillingContract.sol:

import "ProductContract.sol";    
contract BillingContract {  
    ProductContract pc;  
    address PC_Address;  
    function BillingContract (address p) {  
        PC_Address = pc;  
        pc = ProductContract(p);  
    function getVal (uint p_id) returns (uint v) {  
        return pc.getVal(p_id);  
    }  
 }

This results in an error on compiling:

Error: Library "DataSet" declared twice (will create ambiguities during linking).  
    library DataSet {
    ^
Spanning multiple lines.  
The other declaration is here: DataSet.sol:3:1: 
    library DataSet {   
    ^
Spanning multiple lines.
Compiliation failed. See above.  

There is a form of transitive dependence on the above contracts - when I try to use all the contracts in a single '.sol' file, the compilation occurs just fine. Is there a way in which the '.sol' files can be separated and compiled properly? Please advise!

3
  • What environment are you compiling in. I've had these dependancy stack issues before with older versions of Solidity in Browser Solidity, though I thought they been cleaned up. Try importing the library into BillingContract.sol also and see if it compiles
    – o0ragman0o
    Apr 2, 2017 at 4:02
  • I am using truffle v 3.x to facilitate the compilation of these contracts - using solidity ^0.4.4 (a higher version of solidity doest seem possible to use in truffle). Tried your suggestion, but still it results in the same error as above
    – skarred14
    Apr 2, 2017 at 7:45
  • Even after updating the solidity version to ^0.4.8, i see the same issue. I have out the dependent contract BillingContract.sol in the following order - still no resolution for the above error ``` import "DataSet.sol"; import "ProductContract.sol"; ```
    – skarred14
    Apr 2, 2017 at 17:15

1 Answer 1

1

I actually had similar issue in my contract and it was due to the fact that I did not include version pragma in the header :

pragma solidity ^0.4.4;

solved my problem.

hope it helps

1
  • Thanks! Tried 0.4.4, 0.4.6, 0.4.7 as well but to no avail. Doesn't look like its a compiler version issue
    – skarred14
    Jun 9, 2017 at 21:56

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.