New Delhi: The ruling and opposition parties in India condemned US President Donald Trump's comments this week mocking New Delhi's role in war-torn Afghanistan, where the South Asian country has invested billions of dollars in economic projects and military training.

The United States and India have drawn closer in recent years as they seek ways to counter-balance China's spreading influence across Asia.

But Trump`s apparent bid to undermine India's developmental work in Afghanistan has annoyed not just politicians but also many ordinary Indians.

Trump said on Wednesday he got along very well with Prime Minister Narendra Modi but that PM Modi was "constantly telling me he built a library in Afghanistan".

"You know what that is? That`s like five hours of what we spend," Trump told reporters at the White House. "And we are supposed to say, `oh, thank you for the library`. I don`t know who is using it in Afghanistan."

It was not immediately clear which library Trump was referring to, but Bharatiya Janata Party (BJP) as well as the Congress were united in their criticism of the US president.

India has centuries-old ties with Afghanistan and both accuse common neighbour Pakistan of not doing enough to stop Islamist militants operating on their territory. Pakistan denies the charges.

"May be Trump should know that while he is decrying every other help in Afghanistan, India has been building not only libraries, but roads, dams, schools and even parliament building," Ram Madhav, BJP general secretary, said on Twitter. "We are building lives, for which the Afghan people thank us, no matter what others do or don’t."

Congress said India did not "need sermons from the US on Afghanistan".

The United States has 14,000 troops in Afghanistan, with reports it may be set to withdraw more than 5,000, a sign Trump`s patience is thinning with America`s longest war. Trump has already decided to pull all U.S. troops out of Syria.

PM Modi's office did not respond to an email seeking comment. Reuters could not reach the White House outside regular business hours in the United States.

India is the biggest South Asian donor to Afghanistan, spending around $2 billion on reconstruction and rehabilitation, according to the Indian embassy in Kabul. Over the past few years India has helped Afghanistan build roads, erect power transmission lines and construct a parliament building.

Kabul has not yet responded to Trump`s comments.

Afghanistan’s national security advisor, Hamdullah Mohib, is meeting his Indian counterpart Ajit Doval and other officials in New Delhi on Friday.

"Trump mocked India, a key US non-NATO partner that`s done major development work in Afghanistan, for building a library there," Michael Kugelman, South Asia senior associate at the Washington-based Wilson Center think-tank, said on Twitter. "Sigh."