Fix compilation when --as-needed is used during linking