My opinion isn't popular or well-liked, but I think it's closest to the truth.
The answer is you can't fix it. There are always going to be people who cannot (or will not) function in a "normal", conformist way. Whether due to mental illness, addiction, or personality traits such as antisocial behaviour, certain human beings will always end up cycled out of rotation and onto the streets.
What you can do is offer services and a leg up to those who want it. Or those who can reasonably be expected to benefit. Anyone who needs mental health services or addiction treatment should be able to get it. Anyone who needs a shelter bed should have one. Anyone who wants to apply for a job should be able to get help with procuring a temporary address and/or contact means, filling out applications, adequate clothing for interviews, etc. Those who don't want such things should be left to pursue their own path, wherever it leads. (Sorry if that sounds harsh, but some folks are just broken beyond repair, and there is nothing that can be done in any long-term or sustainable way.)
What you can't do is force people into treatment or shelters and pretend the issue is they just need cheap rent or "affordable" housing (whatever that means). If you gave every homeless person a free apartment, many of those units would end up neglected, damaged, or abandoned. If you gave them all a job, some wouldn't show up, or disappear after the first pay check. As others have already said, this is first and foremost a mental health issue. Even the best of intentions can dissipate into the fog of the mentally ill mind. Often, they simply can't get "there", even if it is in their best interest.
At some point, we need to accept the harsh truth that some people simply cannot be helped. In a way, it's similar to how we are perfectly ok with putting an animal out of it's misery to save it from suffering, yet insist our loved ones writhe in excruciating agony until the very end. We have to dispel with idealistic and naive notions about saving everyone and just let some of them go. Focus on those who have legitimately hit hard times and just need (and are seeking) that helping hand to get them back into the game.
I think it can't said enough, however, that many of the homeless find themselves there because the the help they needed was NOT available at a time when they were willing and able to accept it.
Telling someone who is ready to battle their drug or alcohol addiction that out-patient help might be available in six months doesn't cut it; and in-patient help being all but non-existent (for free) is a further issue (some folks have to be out of the environment in which they find themselves in order to shed their ills).
Further, the notion that its as simple as providing treatment for a week or a month or two and then you're on your own is a further problem.
There is a need for on-going support and/or supportive housing, for some folks, for at least several months, sometimes longer.
For other forms of mental illness, the issues are quite similar in many cases.
While lack of funds for prescriptions may be an issue in some cases; as might the absence of proper housing (one could imagine a stiff drink sounding rather appealing if one was sleeping on the street on a cold night).
***
Its an absolute truth that not everyone wants help; and that some, regrettably may be beyond any conventionally available help at this time.
But that can't be an excuse for inaction, or not trying.
Nor should we fail to note, that the cost of hostels alone is over $3,000 per cot, per month.
That completely ignores secondary healthcare, justice system and economic costs from letting someone fall so far.
A great deal of investment, even if superficially expensive, can be justified by the pay-off, even if it takes some time, and even if it doesn't work out, every time.