Solved

C++ Second Defintion Ignored Warnings... struct objects header & CPP

Posted on 2011-03-21
3
821 Views
Last Modified: 2012-08-13
I am unable to link my project without "second definition ignored' warnings.
1>__NDatabase.obj : warning LNK4006: "struct _DataTypeMap * DataTypeMap" (?DataTypeMap@@3PAU_DataTypeMap@@A) already defined in __NVTransfers.obj; second definition ignored

Are my header and CPP files correctly configure for a object type of struct ?

Header file
#pragma once
#include "StaticData.h"

#ifndef _DataTypeMap_IMPLEMENT_
#define _DataTypeMap_IMPLEMENT_

struct _DataTypeMap
{
	LPCTSTR Name;
	UINT    OrdinalType;
	LPCTSTR SQLInteger;           // SQL_INTEGER  = 4
	LPCTSTR SQLSmallInt;          // SQL_SMALLINT = 5
	LPCTSTR SQLTinyInt;           // SQL_TINYINT  = -6
	LPCTSTR SQLBigInt;            // SQL_BIGINT   = -5
	LPCTSTR SQLReal;              // SQL_REAL     = 7
	LPCTSTR SQLNumeric;           // SQL_NUMERIC  = 2
	LPCTSTR SQLDecimal;           // SQL_DECIMAL  = 3
	LPCTSTR SQLFloat;             // SQL_FLOAT    = 6
	LPCTSTR SQLDouble;            // SQL_DOUBLE   = 8
	LPCTSTR SQLLongVarBinary;     // SQL_LONGVARBINARY = -4
	LPCTSTR SQLChar;              // SQL_CHAR     = 1
	LPCTSTR SQLVarChar;           // SQL_VARCHAR  = 12
	LPCTSTR SQLLongVarChar;       // SQL_LONGVARCHAR = -1
	LPCTSTR SQLTimeStamp;         // SQL_TIMESTAMP = 11, SQL_TYPE_TIMESTAMP = 93
	LPCTSTR SQLDateTime;          // SQL_DATETIME = 9
	LPCTSTR SQLDate;              // SQL_DATE     = 9, SQL_TYPE_DATE = 91
	LPCTSTR SQLTime;              // SQL_TIME     = 10, SQL_TYPE_TIME = 92
	LPCTSTR SQLBit;               // SQL_BIT      = -7
	LPCTSTR SQLVarBinary;         // SQL_VARBINARY = -3
	LPCTSTR SQLNull;              // 
} DataTypeMap[] = {
	_T("Default"),                 SQLSRV, _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("datetime"), _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Oracle"),                  ORACLE,     _T("integer"), _T("integer"),  _T("integer"), _T("number"), _T("float"), _T("numeric"), _T("number"), _T("float"), _T("number"), _T("longvarbinary"), _T("char"), _T("varchar2"), _T("longvarchar"), _T("timestamp"), _T("date"), _T("date"),     _T("time"), _T("bit"), _T("raw"),        _T("null"),
	_T("Ingres"),                  OPEN_INGRES,     _T("integer"), _T("integer"),  _T("integer"), _T("number"), _T("float"), _T("numeric"), _T("number"), _T("float"), _T("number"), _T("longvarbinary"), _T("char"), _T("varchar"), _T("longvarchar"), _T("timestamp"), _T("date"), _T("date"),     _T("time"), _T("bit"), _T("raw"),        _T("null"),
	_T("Oracle8"),                 ORACLE,     _T("integer"), _T("integer"),  _T("integer"), _T("number"), _T("float"), _T("numeric"), _T("number"), _T("float"), _T("number"), _T("longvarbinary"), _T("char"), _T("varchar2"), _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("raw"),        _T("null"),
	_T("Microsoft SQL Server"),    SQLSRV, _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("image"),         _T("char"), _T("varchar"),  _T("longvarchar"), _T("datetime"),  _T("datetime"), _T("datetime"), _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Rdb"),                     RDB,        _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Access"),                  ACCESS,     _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("datetime"), _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Informix"),                INFORMIX,   _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Sybase"),                  SYBASE,     _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("datetime"), _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("DB2"),                     DB2,        _T("integer"), _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("MySQL"),                   MYSQL,      _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double"),           _T("longblob"),      _T("char"), _T("varchar"),  _T("longtext"),    _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("tinyint(1)"), _T("varbinary"), _T("null"),
	_T("TurboImage"),              TURBOIMAGE, _T("integer"), _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("numeric"), _T("float"), _T("double"),           _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Attunity Connect Driver"), ATTUNITY,   _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
	_T("Rename Me"),               CONNX,      _T("int"),     _T("smallint"), _T("tinyint"), _T("bigint"), _T("real"), _T("numeric"), _T("decimal"), _T("float"), _T("double precision"), _T("longvarbinary"), _T("char"), _T("varchar"),  _T("longvarchar"), _T("timestamp"), _T("datetime"), _T("date"),     _T("time"), _T("bit"), _T("varbinary"),        _T("null"),
};
#endif

Open in new window


CPP  File
#include "stdafx.h"
#include "_DataTypeMap.h"

Open in new window

0
Comment
Question by:TimPeer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
DonConsolio earned 250 total points
ID: 35186522
"second definition ignored' warning means: "struct _DataTypeMap * DataTypeMap" is
compiled into  __NDatabase.obj and into __NVTransfers.obj, but only one object with
the same (mangled) name  (i.e. same name and same prototype) can be linked into
your executable.

Header files should be used for definitions, but not for actual variables, as they tend to be
included multiple times.

To get rid of your problem
 
// in header file: the prototype
// can be included multiple times
-----------------------------------
struct _t_DataTypeMap
{
.....
};
typedef struct _t_DataTypeMap _DataTypeMap;

extern _DataTypeMap DataTypeMap[];
-----------------------------------

in ONE c++ file (e.g. main.cpp)
-----------------------------------
_DataTypeMap DataTypeMap[] = {
	_T("Default"),                 SQLSRV, _T("int"),     
....
};
-----------------------------------

Open in new window

0
 
LVL 34

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 35187187
if you have a manager class (singleton class) which handles the DataTypeMap i would suggest to make the definition of the array a member of this class. this class also could provide functions to access the array from other classes if needed.

generally, you can't put a definition into a header file cause each cpp which includes the header would create the same symbol (a named global variable pointing to some part of memory) again what gives linker error. header files only may contain declarations, for example of struct/class or function prototypes, extern declarations as told by DonConsolio, preprocessor macros enumerations, and inline code.

Sara
0
 

Author Closing Comment

by:TimPeer
ID: 35196371
I abandoned the struct type and embedded in a class with the CMapStringToOb so will split the points since I didn't select either solution.

Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question