How to develop compassion while avoiding attachment? The Buddha stressed compassion in his teachings. It seems that the more one tries to be compassionate towards people, a natural tendency of attachment develops. For example, it seems that if I try to practice compassion towards my close family (and focus my mind on helping them), then I develop more attachment for them, and I feel closer to them and the pain of separation increases. Is it wrong that I want to feel closer to them? Did the Buddha have any advice about developing compassion while avoiding attachment (and other side effects like pride) ?
I am personally not aware of any direct advice the Buddha gave about developing compassion without attachment since the majority of the Buddha's teachings are about developing non-attachment &amp; the minority of teachings are about developing compassion. In general, the compassion teachings are generally related to cultivating non-harming, non-hatred &amp; non-cruelty and also about teaching the dhamma to others. In other words, the compassion teachings are generally not about how to help others in more worldly or mundane ways. 

The teachings of the Buddha are generally separated as: (1) teachings for monks; and (2) teachings for laypeople. The teachings for monks focus on non-attachment where as the teachings for laypeople rarely mention non-attachment. 

In general, the Buddha encouraged laypeople to do good so they develop personal pride or self-respect in relation to their good actions (eg. Anana Sutta &amp; Samajivina Sutta). 

For example, in With Brahma (Itivuttaka 4.7) and in the Sigalovada Sutta, the Buddha discusses the compassionate role &amp; duties of parents &amp; family members but does not mention non-attachment. In the Piyajatika Sutta, the Buddha says to a man his grief towards his dead son comes from his love but does not teach non-attachment. 

In SN 42.12, the Buddha eventually refers to a man who uses his wealth to help his family without being attached to it, "seeing the danger in it, understanding the escape" but does not go into any details. That said, "seeing the danger &amp; understanding the escape" are a stock teaching for monks in the suttas, where the "danger" (ādīnava) is attachment &amp; the "escape" (nissaraṇa) is the non-attachment of the eightfold path.

Therefore, I think non-attachment can be developed by comprehending the danger or suffering of attachment. As the Buddha taught about the 1st noble truth: "This suffering (of attaching to the five aggregates) is to be comprehended". 

In the Udayi Sutta, it is mentioned teaching others with compassion &amp; without harming oneself. 

In the Attavagga in the Dhammapada, it is again mentioned doing good without hurting oneself. 

The Attavagga holds the principle that each individual must help themself. The Maggavagga has the phrase: " You yourselves must strive; the Buddhas only point the way". 

These accord with the practise of equanimity (upeka), where it is reflected each individual is the owner of their actions. 

Compassion (karuna) is one of the 4 brahma vihara, which also include metta, mudita &amp; equanimity (upeka). Here, helping others (compassion) is balanced with the understanding (upeka) that we try to help others to help themselves; thus ultimately, others are responsible for their lives. 

This old booklet may be helpful for you: 

http://www.buddhanet.net/pdf_file/4sublime_states.pdf
http://www.accesstoinsight.org/lib/authors/nyanaponika/wheel006.html