Comparative advantage theory (like most of economy) is a misleading simplification.
Historicaly the countries that were on the "low profit" end of international trade and followed the comparative advantage theory advice - lost (see Argentina), and the countries that contrary to the theory tried to move to more complex products/services and bigger profits - won (see Germany, USA), even if they had to abandon their comparative advantages, suffer international trade restrictions, etc to get there.
It turns out industrialization not only makes you better at producing machines - it also makes you better at producing food, and almost everything else. Meanwhile producing food just produces food.