Skip to the content ForoHackers
Log inJoin

C linker: multiple definition of counter. There is ONE header and I will die on this hill

Build systemsCCompilers
#15685 · · Quote · Report

multiple definition of 'counter' From the linker. My header contains int counter = 0; and has an include guard. bump.c includes it. show.c includes it. There is one physical header. I'd like to know who is printing the second one behind my back.

#15797 · · Quote · Report

Of course you've put a guard on the header. We are professionals. Please frame the guard and tell us which translation unit can see the one that went up next door.

#15798 · · Quote · Report

Two .o files. Both compiled separately without a peep. Complaint only when the two get married. Your tone is shit but I suspect you've just told me the answer.

#15799 · · Quote · Report

Im Header nur extern int counter;. Genau eine Definition in einer .c-Datei. Der Include-Guard bewacht jeden Präprozessorlauf für sich. Wer nach der Hochzeit aufräumt, steht woanders.

#15810 · · Quote · Report

¿y si le pongo static delante? a mí me deja enlazar, estoy recibiendo señales mixtas de la única autoridad que me importaba.

#15811 · · Quote · Report

Then each translation unit gets its own counter. bump can increment its own copy all evening while show is still staring at zero. One extern declaration and one definition: bump once, show prints 1.

#15812 · · Quote · Report

confirmo con dos contadores: subí el de la cocina y en el comedor seguían pidiendo mesa. dos cocinas no me pagáis, así que me paso al extern.

#15813 · · Quote · Report

Lol at the person who privately recommended ASan. I use a sanitizer when the code is running. We're currently at the rather exciting stage of NOT HAVING A PROGRAM. The linker would like a moment of our time.

#15814 · · Quote · Report

My favourite offer was "send me the executable and I'll look". Mate if I ever produce an executable I'm taking it out for a drink.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply