?
Solved

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

Posted on 2011-03-21
3
Medium Priority
?
843 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 1000 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 35

Assisted Solution

by:sarabande
sarabande earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

649 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