I'm working on a Mega 2560 board. I plan to move my project to a custom PCB using a bare ATmega2560 microcontroller (same as the one on Arduino). From what I have researched, there is no clear answer to my question.
Can I program the Arduino with the Arduino IDE and later port all this code to my own PCB? I see that the Arduino IDE creates .cpp files corresponding to all the sketches.
I understand that I would have to keep all referenced Arduino pins and peripherals from the Eagle schematics.
EDIT: As pointed out in the answers below, you can use Arduino code on your own PCB, provided you don't use any third party libraries. You can use the hex files the Arduino IDE generates to program the microcontroller on the PCB via Atmel Studio or using Arduino as ISP.