1

I have set up a simple program which reproduces the error:

// main.cpp
#include "header.h"

int main()
{
    return 0;
}

Now the header file for the function:

// header.h
#ifndef __HEADER_INCLUDED
#define __HEADER_INCLUDED
float const funct();
#endif

And the cpp file for the function:

// header.cpp
#include "header.h"

float const funct()
{
    return 1.0f;
}

Compiling this, I get this error:

Release\header.obj : warning LNK4042: object specified more than once; extras ignored

Am I missing something obvious or is this just another VS bug/peculiarity?

quant
  • 21,507
  • 32
  • 115
  • 211
  • 2
    You're using a [reserved identifier](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – chris May 30 '13 at 00:50
  • In VS 2008 SP1 your program works fine. I think vs 2012 may response deferentially for `Reserved identifiers` – Nayana Adassuriya May 30 '13 at 01:01
  • @chris: what is a reserved identifier in this case? `__HEADER_INCLUDED`? – Violet Giraffe May 30 '13 at 07:08
  • @VioletGiraffe, Yes, double underscores are a no-no (and if you change it to one, take care not to begin with an underscore and a capital, or even just an underscore in the global scope). – chris May 30 '13 at 07:10

1 Answers1

-1

Add

#pragma once

at the top of each of your files. This tells the linker to ignore extra includes and gets rid of the warning.