atypical LNK2005; not the usual
LNK2005 in an MFC project, VS2008:
I have the common LNK2005 error, but the cause is not inclusion of a .cpp
file. To be sure, I searched the project. There were more of these, but some
were stopped by removing unnecessary ???.h??? includes. But in this case,
DualDoc.cpp must have an include of IteratorMonitor.h, because there is a
call to a function member of IteratorMonitor.
Two classes are involved: CdualDoc, which has a member function that calls a
static function member of IteratorMonitor.
This error refers to a simple global function pointer. It wasn't originally
???void???, but I simplified the data type in my diagnostic efforts. Both of the
flagged data structures are defined in IteratorMonitor.h, and ONLY there:
error LNK2005: "void * IteratorMonitorView" (?IteratorMonitorView@@3PAXA)
already defined in dualDoc.obj
error LNK2005: "class CArray<struct Thread_params,struct Thread_params &>
MyThreadTable" (?MyThreadTable@@3V?$CArray@UThread_params@@AAU1@@@A) already
defined in dualDoc.obj
1>D:\VS2008\Projects\dual\Debug\dual.exe
And finally, fatal error LNK1169: one or more multiply defined symbols
found. Whatever this is, it is not the usual newbie error of multiple
definitions. But the compiler seems to interpret the inclusion of
IteratorMonitor.h, as such.
(Call in DualDoc.cpp to function in IteratorMonitor.cpp:
void CdualDoc::OnEditStartsolver()
{
// TODO: Add your command handler code here
// IteratorMonitor::SetView( this );
if( ! IteratorMonitor::SetView( this ) && this->iter_state != PAUSE)
IteratorMonitor::OnIteratorMonitor();
this->iter_state=RUN;
int mesh_length, mesh_height;
mesh_length = dimensions.mesh_length; mesh_height = dimensions.mesh_height;
int i,j,k;
for( i = 0; i < mesh_length; i++){
for (j=0; j < mesh_height; j++) {
Mesh2D(&Mesh0,i,j).pressure= Mesh2D(&Mesh0,i,j).Vx=Mesh2D(&Mesh0,i,j).Vy=0;
}
}
IteratorMonitor::initiate_solver( *this );
}
IteratorMonitor.h:
#pragma once
#include "Stdafx.h"
#include "afxwinappex.h"
#define THREAD_PRESSURE_DONE (WM_APP+1)
#define THREAD_NAVSTOKES_DONE (WM_APP+2)
#define THREAD_CORRECT_DONE (WM_APP+3)
/* class Thread_params : public CObject
{
public:
CWinThread* thread; CdualDoc* p_MeshDoc; int x_min, y_min, x_max, y_max;
};
*/
struct Thread_params { CWinThread* thread; CdualDoc* p_MeshDoc; int x_min,
y_min, x_max, y_max; };
#define THREADTABLE_SIZE 16
typedef CArray<Thread_params, Thread_params&> Thread_Table;
Thread_Table MyThreadTable;
// IteratorMonitor view
class IteratorMonitor : public CEditView
{
DECLARE_DYNCREATE(IteratorMonitor)
protected:
IteratorMonitor(); // protected constructor used by dynamic
creation
virtual ~IteratorMonitor();
public:
VOID IteratorMonitorWrite(int, int, int );
CView *GetView();
// static CView *pView;
// static HWND MonitorHandle;
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
DECLARE_MESSAGE_MAP()
public:
static VOID OnIteratorMonitor();
static int SetView( CdualDoc* );
static VOID initiate_solver(CdualDoc& );
static void solver_step( CdualDoc& );
static void NavStokes_step( CdualDoc*, int, int, int, int );
static UINT __cdecl NavStokes_Thread( Thread_params& );
static UINT __cdecl Pressure_Thread( Thread_params& );
static UINT __cdecl Correction_Thread( Thread_params& );
static float pressure_solver_step( CdualDoc*, int, int, int, int );
static void solver_correction_step( CdualDoc*, int, int, int, int );
static void NavStokes_interior( CdualDoc::Mesh_array*, int&, int& );
static void NavStokes_N_boundary( CdualDoc::Mesh_array*, int &, int & );
static void NavStokes_S_boundary( CdualDoc::Mesh_array*, int &, int & );
static void NavStokes_E_boundary( CdualDoc::Mesh_array*, int &, int & );
static void NavStokes_W_boundary( CdualDoc::Mesh_array*, int &, int & );
afx_msg LRESULT On_Thread_NavStokes_Done( WPARAM, LPARAM );
afx_msg LRESULT On_Thread_Pressure_Done( WPARAM, LPARAM );
afx_msg LRESULT On_Thread_Correct_Done( WPARAM, LPARAM );
};
/*
CView *IteratorMonitor::pView;
HWND IteratorMonitor::MonitorHandle;
*/
VOID *IteratorMonitorView;
Dualdoc.h:
// dualDoc.h : interface of the CdualDoc class
//
#pragma once
//class dialog_mesh_size;
#include "Stdafx.h"
#include "resource.h"
#include "dialog_mesh_size.h"
const int NSIDES=2;
enum direction{N,S,E,W,C};
#define CellDimX (float)1.0
#define CellDimY (float)1.0
#define CellDimXx2 (float)(2.0*CellDimX)
#define CellDimYx2 (float)(2.0*CellDimY)
#define CellVol (float)( CellDimX * CellDimY )
#define CellVol_sq (float)( CellVol * CellVol )
#define CellDimX_sq (float) ( CellDimX * CellDimX )
#define CellDimY_sq (float)( CellDimY * CellDimY )
#define Visc (float)1.0
#define Rho (float)1.0
class Cell:CObject
{
public:
float Vx, Vy, pressure, pressure_correction, residual;
};
class CdualDoc : public CDocument
{
protected: // create from serialization only
CdualDoc();
DECLARE_DYNCREATE(CdualDoc)
// Attributes
public:
enum run_state{RUN, PAUSE, STOP} iter_state;
// Operations
public:
static CdualDoc * GetDoc();
// Overrides
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL AddFloatView();
dialog_mesh_size dimensions;
// Implementation
public:
virtual ~CdualDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
typedef CArray<Cell, Cell&> Mesh_array;
public:
Mesh_array Mesh0, Mesh1;
Mesh_array* pMesh, *pMesh_previous;
protected:
// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEditStartsolver();
afx_msg void OnEditStopsolver();
afx_msg void OnEditPausesolver();
afx_msg void OnEditResumesolver();
};
class Submesh:CObject {
public:
CdualDoc* p_MeshDoc;
int x_min, x_max, y_min, y_max;
};