PARIS, JULY 23 -- French Prime Minister Jacques Chirac's much-heralded attempt to improve contacts with Iran has foundered against the background of France's long-established and highly lucrative military ties with Iraq.

With France and Iran now in a dangerous confrontation and French diplomats trapped in Tehran, the search for friends in Ayatollah Ruhollah Khomeini's Islamic government seems, in retrospect, to have been doomed from the start for a nation that, alongside the Soviet Union, had become one of Iraq's largest arms suppliers.

When an Iraqi pilot attacked the USS Stark on May 17, killing 37 U.S. sailors, for example, he fired a French-made AM39 Exocet missile from under the wing of a French-made F1 Mirage warplane and likely returned home with guidance from a French-made radar system on the ground.

When Iraq needed to replenish artillery and munitions stocks last February after an Iranian offensive near Basra, Deputy Prime Minister Tariq Aziz flew to Paris for talks with Chirac and a visit by Iraqi experts to the headquarters of Thomson CSF, a leading French arms manufacturer.

Gen. Abdul Jabbar Chanchall, the Iraqi official in charge of military supplies, had come here only three weeks earlier to help reschedule a debt to France estimated at more than $4 billion accumulated in large part through deferred-payment purchases of French weaponry since the Iran-Iraq war broke out in 1980.

Like President Reagan in his search for Iranian moderates, Chirac apparently tried what turned out to be impossible because of a burning desire to obtain Iranian help in freeing hostages kidnaped in Lebanon. Unlike the Reagan administration, however, Chirac began the enterprise with a clearly defined French policy of supplying Iraq already in effect -- a policy that had been initiated more than a decade ago by Chirac himself.

French officials have said Chirac made it clear to Iran from the start of his attempt at renewed relations, in April 1986, that French policy in the Middle East would remain unchanged, including support for Iraq. Foreign Minister Jean-Bernard Raimond reiterated this in a radio interview today.

"When we told the Iranians we were ready to normalize our relations in the framework of certain limits and without changing our Middle East policy, they understood very well," he said.

Whether they understood or not, Iranian officials have been equally clear in explaining that French neutrality in the seven-year-old Persian Gulf war was a condition for improved relations. Within days of Chanchall's visit here to secure more French weapons on credit, for example, a high Iranian official also visited and insisted that French military support for Iraq must stop if Paris and Tehran were to work together as Chirac urged.

The official, Ali Ahani, director of the Foreign Ministry's Europe and America section, held a news conference to lay out the three conditions set down by the Islamic leadership in Tehran for normalized relations. These were French neutrality in the war, expulsion of anti-Khomeini activists based in Paris and repayment of a billion-dollar French debt to Iran contracted in 1974 during the shah's rule.

Chirac's government paid back $330 million of the debt and was negotiating on ways to liquidate the rest. It also forced Massoud Rajavi, leader of the People's Mojahedin resistance movement, to move his headquarters from a Paris suburb to Iraq. But nothing was done to end the military sales relationship with President Saddam Hussein in Baghdad and, French officials declared, nothing would be.

Persistent reports in the French press have said Chirac's government led Iranian officials to understand that if French hostages were released in Lebanon, a way would be found for Iran to buy French military equipment as well. But Raimond has categorically denied this, insisting French envoys from the earliest contacts on told Iran that arms sales were out of the question.

In any case, the repeated Iranian demand -- French neutrality in the war -- and the consistent French position -- that sales to Iraq will go on -- seemed to create an irreconcilable contradiction in Chirac's policy from the beginning.

France long has maintained cordial relations with Syria, a traditional enemy of Iraq, without having to renounce its friendship with Baghdad. But Iran's fundamentalist leadership emphasized that such an arrangement was impossible with Tehran, even if both countries could profit from it, as long as the war with Iraq dominates life in Iran.

"How can you proclaim friendship and alliance with an aggressor?" the Iranian charge d'affaires, Gholam Reza Haddadi, asked a French interviewer in February. "We demand French neutrality in this war that has been imposed on us. We demand a halt in all military aid to Iraq, to this country that threatens hundreds of villages, bombs civilian populations and uses chemical weapons."

The importance of French ties to Iraq seemed particularly visible in light of Khomeini's pledges to continue fighting until Saddam Hussein is no longer the leader of Iraq. In his speeches, Khomeini has depicted the conflict as partly a grudge war where ordinary calculations of national interest might not always prevail.

Chirac has been personally identified with Saddam Hussein since, as prime minister under then-president Valery Giscard d'Estaing, he advocated increased dealings with Iraq and negotiated an agreement in 1975 for French construction of a nuclear reactor just outside Baghdad. The plant was destroyed by Israeli bombers in June 1981.

French ties to Hussein's government survived, however. The Socialist government that came to power in May 1981 pledged in principle to rebuild the plant, although the Iran-Iraq war and other difficulties so far have prevented any agreement for doing so.

As the conflict dragged on, France also continued to sell Iraq missiles, electronics, artillery, ammunition and Mirage warplanes, arranging partial payment in Iraqi petroleum. Despite reservations expressed by the United States and Britain, France sold Iraq five advanced Super Etendard aircraft in October 1983.

This gave Iraqi forces increased range for attacks with Exocet missiles against shipping in and out of Iranian oil ports. Iran threatened then to close off the Persian Gulf if Iraq used the planes to attack petroleum tankers, helping set up conditions for the present crisis involving U.S. military forces in the gulf.