You open the cannon by getting 120 stars. After you've gotten 120 stars, you can go outside and fire the cannon. You do not need to find a Bob-omb buddy.
Chat with our AI personalities
Collect 120 stars
Get 63 shine sprites, there are actually 64 shine sprites but that last one, you can only get it if you've had the cannon open, because it leads you to the shine sprite if you use it.
Sadly (I do know how you feel, you know) the only way open the cannon outside the castle is to collect all 150 stars. When you have done this, just walk up to it and it should be open. If you have an Action Replay card, however, there is almost certainly a cheat you can use to get the cannon before this.
I haven't done it yet, but you're supposed to collect all 120 stars. After that, the Canon should be open. Also, you're talking about super mario 64 right, because that's the only "canon outside the castle" I know of. Anyway, there you go.
If you mean the outside cannon you have to collect 120 stars. If you're talking about the ones in the courses you have to talk to a bob-bob buddy (pink bob-bob).