No idea is created out of nothing, so I'm just wondering who came before Marx that would have influenced his thinking on the subject.
Marx was commissioned by the Communist League to write The Communist Manifesto in 1847. Its doctrines were refined through debates inside the Communist League.
One key influence lies in Marx's personal background. He was born in Trier, a city in Rhineland-Palatinate that had been part of French territory during the years 1805 to 1814, and French revolutionary thought had left its imprint on the intellectual spirit of the city. Marx came into intellectual contact with French thinkers via a family friend, Baron Ludwig von Westphalen, who introduced him to the works of Saint-Simon. He was further influenced by a Jewish cultural background and contemporary north German Protestant views regarding religion.
He and his co-author Engels were also were also impacted by other currents of political thought, particularly socialism. The socialists offered valuable ideas in the working-class debate and Engels refers to them directly, naming Owen, Fourier and Cabet specifically.
All this said, Marx's major work of theory is actually Capital, so let's take a look at that as well.
Although often regarded as a work of political economy, Capital combined dialectics, materialism, economic theory and socialist visions to form a coherent critique of the system of capitalism. Marx sought to unravel the internal contradictions governing the laws of motion of capitalism. Hegel inspired his adoption and amendment of dialectics as the key means of achieving this. (Dialectics is a philosophy that considers that change is produced by internal contradictions, which generate transformation.) The materialist philosophy of Ludwig Feuerbach provided the means to anchor the dialectics of change in societal struggles over material resources and the means of producing wealth. Marx also began to master the doctrines of the school of classical political economy. Theories developed by Adam Smith and more consistently by David Ricardo, particularly the labour theory of value, influenced his approach to the material manifestation of dialectical contradictions, which focused on the class struggle between capital and labour.
As we've seen, Marx, like Engels, was also influenced by socialist models, especially a political philosophy he termed called utopian socialism, e.g. the theories of Charles Fourier, Saint-Simon and Robert Owen played an important role in developing Marx’s conceptual framework of an alternative socio-economic system that would replace capitalism – when its internal contradictions led to the overthrow of the capitalist mode of production and its replacement by a socialist system of production.
There was a wide range of contemporary thinkers who influenced Marx directly. Many of them developed their thoughts in similar directions to Marx and began from similar intellectual starting points. Thus, Marx’s critique of the philosophers Hegel and Feuerbach, and of utopian socialism and political economy, sat neatly in tune with powerful and influential ideas of the day.
In Berlin, the intellectual circles that Marx moved in brought together various trends: philosophical criticism; criticism of religion; and speculation on future societal forms. The 1848 revolutions gave expression to the powerful political ideologies of the day: democracy; nationalism; trade unionism; socialism; anarchism and communism. The entire scientific world was experiencing tumultuous upheaval as was society in general. Philosophical ideas appeared to mirror this epoch of upheaval, and scientific theorisation of societal systems seems now to have been an automatic continuation of such a fluid epoch of intellectual enquiry. In political economy the labour theory of value was the dominant theory at the time.
During Marx's time in Berlin, he joined an intellectual group called the Doctor’s Club where Bruno Bauer and Ludwig Feuerbach were influential figures. They debated the ideas of Hegel, whose legacy gave rise to two sharply conflicting schools. The Left-Hegelians advocated radical criticism of the Prussian state. The Right-Hegelians were conservative supporters of Prussia. Marx sided with the Left Hegelians; however, he came to the conclusion that philosophical speculation should be combined with political action in praxis – which means the unity of theory and action. Feuerbach had developed a materialist criticism of Christianity. Marx’s examination and criticism of both Feuerbach, and Hegelian thought, laid the basis for the philosophy of Marxism, known as dialectical materialism.
Finally, Marx was aware of the ways in which the bourgeoisie was increasingly challenging the autocratic power of the ruling elites in Germany. He met Friedrich Engels - the son of a cotton mill owner - in Paris in 1844, and this meeting was the beginning of their lifelong collaboration. Engels’s intimate knowledge of the English factory system and the life of the working class drew Marx’s attention to these issues. In Brussels he encountered vibrant communist and socialist groups, which influenced his thought and drew him into communist politics. Communist and radical circles were thus a further source of intellectual influence, inspiring his focus on developing a “scientific socialist” doctrine to counter utopian socialist and anarchist trends.
We know pretty well which figures influenced Marx, partly because he developed his thought through writing criticisms of them, or by writing notes on their work.
There's an oft-repeated and pretty accurate claim that the three components of Marxism were German philosophy, French socialism, and English political economy (or economics).
In roughly chronological order, some of the major influences on the young Marx were:
In 1886, Engels wrote a good summary of the early development of Marxism out of German philosophy, called Ludwig Feuerbach and the End of Classical German Philosophy.
Marx's primary texts are quite hard to comprehend if you don't know the figures he's commenting on (or, frequently, attacking). If you're looking for an accessible introduction to how Marx developed his ideas, you could do a lot worse than these introductions, which I often recommend:
If you want to plunge into the young Marx's work, some of the texts where Marx records his interactions with these figures I mentioned above are:
As you can see, Marx really developed his ideas through not just studying other thinkers, but vigorously critiquing their work.
Because his early works are so polemical, and relate to an intellectual milieu that is very different from what exists now, they can be hard to read. But I think tracing the development of his early thought is very important to understand how texts like The Communist Manifesto came into being, so have a look at the secondary sources I've listed if that's a project that interests you.