Sign in to follow this  

LNK4006 warnings and namespaces?

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm having tonnes of problems with LNK4006 errors and have been for quite sometime. I've narrowed down the sources to three parts of the code, both revolve around namepsaces. For interests sake here they are (d3d is a slightly modified code from the '3D Game Programming with DirectX' textbook the PHYSXUTIL/GAME ones are mine): d3d:
#ifndef __d3dUtilityH__
#define __d3dUtilityH__

#include <d3dx9.h>
#include <string>
#include <limits>
#include <vector>
#include <time.h>

#include "../convtext.h"

namespace d3d
{
	//IDirect3DDevice9* device;
	//HWND hw;
	void MsgB(std::string text)
	{
		::MessageBox(0, _towchar(text.c_str()), 0, 0);
	}
	//
	// Init
	//
	bool InitD3D(
		HINSTANCE hInstance,
		int width, int height,
		bool windowed,
		D3DDEVTYPE deviceType,
		IDirect3DDevice9** device, HWND* hw);

	int EnterMsgLoop( 
		bool (*ptr_display)(float timeDelta));

	LRESULT CALLBACK WndProc(
		HWND hwnd,
		UINT msg, 
		WPARAM wParam,
		LPARAM lParam);

	//
	// Cleanup
	//
	template<class T> void Release(T t)
	{
		if( t )
		{
			t->Release();
			t = 0;
		}
	}

	template<class T> void Delete(T t)
	{
		if( t )
		{
			delete t;
			t = 0;
		}
	}

	//
	// Colors
	//
	const D3DXCOLOR      WHITE( D3DCOLOR_XRGB(255, 255, 255) );
	const D3DXCOLOR      BLACK( D3DCOLOR_XRGB(  0,   0,   0) );
	const D3DXCOLOR        RED( D3DCOLOR_XRGB(255,   0,   0) );
	const D3DXCOLOR      GREEN( D3DCOLOR_XRGB(  0, 255,   0) );
	const D3DXCOLOR       BLUE( D3DCOLOR_XRGB(  0,   0, 255) );
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) );
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) );
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) );

	//
	// Lights
	//

	D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
	D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
	D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);

	//
	// Materials
	//

	D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);

	const D3DMATERIAL9 WHITE_MTRL  = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
	const D3DMATERIAL9 RED_MTRL    = InitMtrl(RED, RED, RED, BLACK, 2.0f);
	const D3DMATERIAL9 GREEN_MTRL  = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
	const D3DMATERIAL9 BLUE_MTRL   = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
	const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);

	//
	// Bounding Objects
	//

	struct BoundingBox
	{
		BoundingBox();

		bool isPointInside(D3DXVECTOR3& p);

		D3DXVECTOR3 _min;
		D3DXVECTOR3 _max;
	};

	struct BoundingSphere
	{
		BoundingSphere();

		D3DXVECTOR3 _center;
		float       _radius;
	};

	//
	// Constants
	//

	const float INFINITY = FLT_MAX;
	const float EPSILON  = 0.001f;

	//
	// Drawing
	//

	// Function references "desert.bmp" internally.  This file must
	// be in the working directory.
	bool DrawBasicScene(
		IDirect3DDevice9* device,// Pass in 0 for cleanup.
		float scale);            // uniform scale 

	//
	// Vertex Structures
	//

	struct Vertex
	{
		Vertex(){}
		Vertex(float x, float y, float z, 
			float nx, float ny, float nz,
			float u, float v)
		{
			_x  = x;  _y  = y;  _z  = z;
			_nx = nx; _ny = ny; _nz = nz;
			_u  = u;  _v  = v;
		}
		float _x, _y, _z;
		float _nx, _ny, _nz;
		float _u, _v;

		static const DWORD FVF;
	};

	struct VertexPT
	{
		VertexPT();
		VertexPT(float x, float y, float z, float u, float v);
		VertexPT(const D3DXVECTOR3& p, const D3DXVECTOR2& uv);

		static IDirect3DVertexDeclaration9* GetDecl(IDirect3DDevice9* device);

		D3DXVECTOR3 pos;
		D3DXVECTOR2 tex0;
	};

	// Nomenclature: 
	//	 P = position component
	//   C = color component
	//   N = normal component
	//   T = texture component

	struct VertexP
	{
		VertexP();
		VertexP(float x, float y, float z);
		VertexP(const D3DXVECTOR3& p);

		static IDirect3DVertexDeclaration9* GetDecl();

		D3DXVECTOR3 pos;
	};

	struct VertexPC
	{
		VertexPC();
		VertexPC(float x, float y, float z, D3DCOLOR c);
		VertexPC(const D3DXVECTOR3& p, D3DCOLOR c);

		static IDirect3DVertexDeclaration9* GetDecl();

		D3DXVECTOR3 pos;
		D3DCOLOR color;
	};

	struct VertexPN
	{
		VertexPN();
		VertexPN(float x, float y, float z,	float nx, float ny, float nz);
		VertexPN(const D3DXVECTOR3& p, const D3DXVECTOR3& n);

		static IDirect3DVertexDeclaration9* GetDecl();

		D3DXVECTOR3 pos;
		D3DXVECTOR3 normal;
	};

	struct VertexPNT
	{
		VertexPNT();
		VertexPNT(float x, float y, float z, float nx, float ny, float nz, float u, float v);
		VertexPNT(const D3DXVECTOR3& p, const D3DXVECTOR3& n, const D3DXVECTOR2& uv);

		static IDirect3DVertexDeclaration9* GetDecl();

		D3DXVECTOR3 pos;
		D3DXVECTOR3 normal;
		D3DXVECTOR2 tex0;
	};


	//
	// Randomness
	//

	// Desc: Return random float in [lowBound, highBound] interval.
	float GetRandomFloat(float lowBound, float highBound)
	{
		if( lowBound >= highBound ) // bad input
			return lowBound;

		// get random float in [0, 1] interval
		float f = (rand() % 10000) * 0.0001f; 

		return (f * (highBound - lowBound)) + lowBound; 
	}

	int GetRandomInt(int lowBound, int highBound)
	{
		if( lowBound >= highBound ) // bad input
			return lowBound;

		// get random float in [0, 1] interval
		float f = (rand() % 10000) * 0.0001f; 

		// return float in [lowBound, highBound] interval. 

		srand ( time(NULL) );
		//int iSecret = rand() % highBound + lowBound;

		return rand() % highBound + lowBound;

		//return (int)( 2 % highBound + lowBound );
	}

	// Desc: Returns a random vector in the bounds specified by min and max.
	void GetRandomVector(
		D3DXVECTOR3* out,
		D3DXVECTOR3* min,
		D3DXVECTOR3* max);

	//
	// Conversion
	//
	DWORD FtoDw(float f);
}

#endif

physxutil:
#pragma once

#ifndef PHYSXUTIL_H
#define PHYSXUTIL_H

#include "physics.h"

namespace PHYSXUTIL
{
	D3DXMATRIX GetMatrixFromActor(NxActor* act);

	NxVec3 NXVecToD3D(D3DXVECTOR3& pos)
	{
		NxVec3 t;t.x = pos.x;t.y = pos.y;t.z = pos.z;

		return t;
	}
}

D3DXMATRIX PHYSXUTIL::GetMatrixFromActor(NxActor* act)
{
	D3DXMATRIX temp;
	D3DXMATRIX temp2;

	D3DXMatrixTranslation(&temp2, act->getGlobalPosition().x, act->getGlobalPosition().y, act->getGlobalPosition().z);


	float d3dMat[16];
	act->getGlobalPose().getColumnMajor44( d3dMat );
	temp = d3dMat;

	temp = temp * temp2;

	return temp;
}

#endif

CGTEXTENSION:
#define _CRT_SECURE_NO_WARNINGS

#ifndef CGTEXT_H
#define CGTEXT_H

#ifdef _MSC_VER
#pragma warning (disable: 4995 4996)
#endif

#define NOMINMAX
#define _CRT_SECURE_NO_DEPRECATE

#include "camera/camera.h"
#include "loader/loader.h"
#include "gui/gui.h"
#include "dinput/DInputMgr.h"
#include "Characters/charactercontrol.h"


//
// Globals
//

namespace GAME
{
	CharacterControl* chars;

	void render(float dt);
	bool LoadNewLevel(int l);
	bool BasicSetup();
	IDirect3DDevice9* Device;
	Camera cam;
	void InitStuff();
	void SetCamera();

	//PhysX declrations...
	PhysX* world;
	float td;

	//loader
	LoaderWriter lw;

	//Gameplay related...
	GamePlay* gp;


	//GUI
	GUI* text;

	//Audio/DirecInput:
	DInputMgr* DInput;
	HWND hw;
	Audio* sound;// = new Audio();


	static const int Width  = 1024;
	static const int Height = 768;


	void RenderGUI();
	void RenderSkyBox();

	void PhysicsSetup();

	bool Setup();
	void LoadSkyBox();

	void SetDirectXLightView();

	void DoLook(float timeDelta);

	bool Display(float timeDelta);
	void render();
};

#endif

Yes, I include all three headers multiple times in different parts of the code, but I also do the same with other classes and don't get LNK4006 warnings. So my question is, is there any relevance between these being namespaces and the LNK4006 warnings and what can I do to prevent the 4006 warnings from occuring while keeping these namespaces? Thanks for any help.

Share this post


Link to post
Share on other sites
It looks like at least some of your problem comes from defining functions in header files and not inlining them. Either declare them inline or move their definition into a source file.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
It looks like at least some of your problem comes from defining functions in header files and not inlining them. Either declare them inline or move their definition into a source file.


Thanks, inlining did help a little bit, but namespace GAME is still giving me the same problems. The functions aren't defined from inside the header file so I'm not sure what to do.

All the LNK4006 warnings are coming from variables rather than functions I'm declaring:

Quote:
1>Display.obj : warning LNK4006: "class CharacterControl * GAME::chars" (?chars@GAME@@3PAVCharacterControl@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "float GAME::td" (?td@GAME@@3MA) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class GUI * GAME::text" (?text@GAME@@3PAVGUI@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "struct IDirect3DDevice9 * GAME::Device" (?Device@GAME@@3PAUIDirect3DDevice9@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class DInputMgr * GAME::DInput" (?DInput@GAME@@3PAVDInputMgr@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class Audio * GAME::sound" (?sound@GAME@@3PAVAudio@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class PhysX * GAME::world" (?world@GAME@@3PAVPhysX@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class GamePlay * GAME::gp" (?gp@GAME@@3PAVGamePlay@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "struct HWND__ * GAME::hw" (?hw@GAME@@3PAUHWND__@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class Camera GAME::cam" (?cam@GAME@@3VCamera@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>Display.obj : warning LNK4006: "class LoaderWriter GAME::lw" (?lw@GAME@@3VLoaderWriter@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class CharacterControl * GAME::chars" (?chars@GAME@@3PAVCharacterControl@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "float GAME::td" (?td@GAME@@3MA) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class GUI * GAME::text" (?text@GAME@@3PAVGUI@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "struct IDirect3DDevice9 * GAME::Device" (?Device@GAME@@3PAUIDirect3DDevice9@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class DInputMgr * GAME::DInput" (?DInput@GAME@@3PAVDInputMgr@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class Audio * GAME::sound" (?sound@GAME@@3PAVAudio@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class PhysX * GAME::world" (?world@GAME@@3PAVPhysX@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class GamePlay * GAME::gp" (?gp@GAME@@3PAVGamePlay@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "struct HWND__ * GAME::hw" (?hw@GAME@@3PAUHWND__@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class Camera GAME::cam" (?cam@GAME@@3VCamera@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>DoControls.obj : warning LNK4006: "class LoaderWriter GAME::lw" (?lw@GAME@@3VLoaderWriter@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class CharacterControl * GAME::chars" (?chars@GAME@@3PAVCharacterControl@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "float GAME::td" (?td@GAME@@3MA) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class GUI * GAME::text" (?text@GAME@@3PAVGUI@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "struct IDirect3DDevice9 * GAME::Device" (?Device@GAME@@3PAUIDirect3DDevice9@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class DInputMgr * GAME::DInput" (?DInput@GAME@@3PAVDInputMgr@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class Audio * GAME::sound" (?sound@GAME@@3PAVAudio@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class PhysX * GAME::world" (?world@GAME@@3PAVPhysX@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class GamePlay * GAME::gp" (?gp@GAME@@3PAVGamePlay@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "struct HWND__ * GAME::hw" (?hw@GAME@@3PAUHWND__@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class Camera GAME::cam" (?cam@GAME@@3VCamera@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>LoadingStuff.obj : warning LNK4006: "class LoaderWriter GAME::lw" (?lw@GAME@@3VLoaderWriter@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class CharacterControl * GAME::chars" (?chars@GAME@@3PAVCharacterControl@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "float GAME::td" (?td@GAME@@3MA) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class GUI * GAME::text" (?text@GAME@@3PAVGUI@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "struct IDirect3DDevice9 * GAME::Device" (?Device@GAME@@3PAUIDirect3DDevice9@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class DInputMgr * GAME::DInput" (?DInput@GAME@@3PAVDInputMgr@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class Audio * GAME::sound" (?sound@GAME@@3PAVAudio@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class PhysX * GAME::world" (?world@GAME@@3PAVPhysX@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class GamePlay * GAME::gp" (?gp@GAME@@3PAVGamePlay@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "struct HWND__ * GAME::hw" (?hw@GAME@@3PAUHWND__@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class Camera GAME::cam" (?cam@GAME@@3VCamera@@A) already defined in CGTEXTENSION.obj; second definition ignored
1>RenderStuff.obj : warning LNK4006: "class LoaderWriter GAME::lw" (?lw@GAME@@3VLoaderWriter@@A) already defined in CGTEXTENSION.obj; second definition ignored


is it just a bad idea to declare variables inside a namespace? I like doing it like this because it's convenient (and I can't use classes because theres another aspect of the code that will start causing problems if I do).

Share this post


Link to post
Share on other sites
The namespace is a red herring. Namespaces aren't handled, or known about, by the linker at all; they're just another decoration on the symbols in the namespace. It looks like you're declaring global variables (in the namespace) in a header file without making them extern.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
The namespace is a red herring. Namespaces aren't handled, or known about, by the linker at all; they're just another decoration on the symbols in the namespace. It looks like you're declaring global variables (in the namespace) in a header file without making them extern.


yep, thanks, I actually just came back to say I made them extern and it solved all the remaining lnk4006 warnings.

Share this post


Link to post
Share on other sites

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this