Now I connect library SafeMath.sol in local project.
pragma solidity ^0.4.15;
import './ERC20.sol';
import './SafeMath.sol';
How can I connect SafeMath.sol from external(non-local) resources or other contracts?
When using import statements you need to have the actual files of the imported contracts as well. In your case, ./SafeMath.sol specifies to the compiler that the contract you are importing is in the same directory with your own contract.
Please see more regarding import paths in : How should we set a import path in solidity?
And in case you want to link your contract to a library: What are the steps to compile and deploy a library in Solidity?
Depends on the development environment you are working with. This article explains everything about importing external code: https://blockheroes.dev/import-external-contracts-libraries/.
For Remix, you just go to OpenZeppelin's git repo and copy the URL and import it:
import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol”;
For Truffle, you have to install the package:
npm install @openzeppelin/contracts
and then import it in your code:
import "@openzeppelin/contracts/utils/math/SafeMath.sol";