Solidity: Fails to compile with -o output dir option if compiled file is in a different then current directory

Created on 1 Feb 2017  路  6Comments  路  Source: ethereum/solidity

For following command:
solc --abi -o '/tmp' './spec/fixtures/greeter.sol'

You get following messages:

Exception during output generation: /tmp/solidity-20170201-68591-whagys/solidity_0.4.9/solc/CommandLineInterface.cpp(469): Throw in function void dev::solidity::CommandLineInterface::createFile(const string &, const string &)
Dynamic exception type: boost::exception_detail::clone_impl<dev::FileError>
std::exception::what: FileError
[dev::tag_comment*] = Could not write to file: /tmp/./spec/fixtures/greeter.sol:greeter.abi

The source filename is concatenated with destination folder with source pathname.

So instead of:
./spec/fixtures/greeter.sol:greeter.abi
we got:
/tmp/./spec/fixtures/greeter.sol:greeter.abi

bug

Most helpful comment

@axic
I found out what happens: it fails when path ends with separator. obj/debug works while obj/debug/ doesn't.

All 6 comments

It does work if you use solc --abi -o /tmp spec/fixtures/greeter.sol does it?

Nope, error message is:

Exception during output generation: /tmp/solidity-20170202-25074-udp7o6/solidity_0.4.9/solc/CommandLineInterface.cpp(469): Throw in function void dev::solidity::CommandLineInterface::createFile(const string &, const string &)
Dynamic exception type: boost::exception_detail::clone_impl<dev::FileError>
std::exception::what: FileError
[dev::tag_comment*] = Could not write to file: /tmp/spec/fixtures/greeter.sol:greeter.abi

It does work if I navigate to spec/fixtures and type:

solc --abi -o /tmp greeter.sol

@marekkirejczyk I think you are using MacOS and this is actually the same problem as #1631. For me on Mac #1648 fixes this.

I think fixed by #1648. Please reopen if persists (see nightly tomorrow or the next release).

@axic
Happenned to me today:

PS C:\Users\Alex\source\repos\Solidity24\Solidity24> solc "Example.sol" -o "obj/Debug/" --bin --abi --overwrite
Exception during output generation: C:\projects\solidity\solc\CommandLineInterface.cpp(505): Throw in function void __cdecl dev::solidity::CommandLineInterface::createFile(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)
Dynamic exception type: class boost::exception_detail::clone_impl<struct dev::FileError>
std::exception::what: FileError
[struct dev::tag_comment * __ptr64] = Could not write to file: obj/Debug/greeter.bin

For this file

pragma solidity ^0.4.11;

contract mortal {
    /* Define variable owner of the type address */
    address owner;

    /* This function is executed at initialization and sets the owner of the contract */
    function mortal() public {
        owner = msg.sender;
    }

    /* Function to recover the funds on the contract */
    function kill() public {
        if (msg.sender == owner) {
            selfdestruct(owner);
        }
    }
}

contract greeter is mortal {
    /* Define variable greeting of the type string */
    string greeting;

    /* This runs when the contract is executed */
    function greeter(string _greeting) public {
        greeting = _greeting;
    }

    /* Main function */
    function greet() public constant returns (string) {
        return greeting;
    }
}

Version: 0.4.21+commit.dfe3193c.Windows.msvc

@axic
I found out what happens: it fails when path ends with separator. obj/debug works while obj/debug/ doesn't.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  3Comments

leviadam picture leviadam  路  4Comments

gitpusha picture gitpusha  路  3Comments

chriseth picture chriseth  路  3Comments

chriseth picture chriseth  路  3Comments