”Vanity of vanities! All is vanity” (Ecclesiastes 1:1).
Ecclesiastes is a transcendental argument against Idolatry. This means that Solomon stands in the shoes of the unbeliever for the sake of argument, and walks the unbelieving world-view to its logical conclusion. Then he looks at life from the believer’s world-view to demonstrate the necessity of faith in the God of the Bible.
If all you live for is what is “under the sun” then your life is meaningless, because you will eventually die and lose everything. On the other hand, if you live for God through faith in Christ your life is meaningful, because everything you have is understood as coming from God’s sovereign hand as a kind gift for you to enjoy.