For deployment I am using remix. When I deploy Hello.sol the compiler typically merges SafeMath.sol as a part of the main contract (Hello.sol) and deploys. This adds up library and main contract's deployment cost as whole. I want to do this operation separately in order to divide deployment cost in to multiple operations.

[Q] Is there any way to first deploy the library contract separately from the main contract and than link it to the main contract on remix? Should I use Truffle or follow different approach for this?

I have following simple contract, remix deploys Hello.sol as as single contract which also includes SafeMath.sol:

Why the same approach does not work on the code piece that I shared on my question, where remix does not separate contract and library? In order to deploy Library separately should it has its own storage? @Mikhail Vladimirov
– alperJul 16 at 23:16

1

This is because you call internal function from the library, and internal functions cannot be called externally, so compiler had no other option than to embed the function into calling smart contract.
– Mikhail VladimirovJul 17 at 5:41

If I replace the interval keyword with public and keep those previously internal functions in the Library, will those cause additional gas usage? @Mikhail Vladimirov
– alperJul 17 at 9:36

1

It is a tradeoff. Internal functions are cheaper to call but increase deployment cost of the contract. External library functions are more expensive to call, but allow to keep byte code size and deployment cost lower.
– Mikhail VladimirovJul 17 at 17:29

I assume external can only be called as though it's calling another contract or library, so additional 2,000 gas for the jump @Mikhail Vladimirov
– alperJul 18 at 13:04

Remix will just go ahead and link the contracts so contracts with libraries work when using the JavsScript VM. I suspect the process works with Injected Web3 but I haven't tried it.
– Rob Hitchens - B9labJul 9 at 18:50