Saltar al contenido ForoHackers

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

Sistemas de compilaciónCCompiladores
#15685 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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

#15811 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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.

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder