Sign in to follow this  

header file - containing......header files

This topic is 4691 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

I have a problem :/ I have a header file that consists of every header file in my project. #ifndef HEADER_LIST_H #define HEADER_LIST_H #include <Windows.h> #include <mmsystem.h> #include <d3dx9.h> #include <d3d9.h> #include "globals.h" #include "render.h" #include "graphics.h" #endif in each header file, I #include "header list.h". In render.h, I have a function "Render()" that calls another function "SetupMatrices". "SetupMatrices()" is located in graphics.h. I get these two errors when I try to compile: render.h(24) : error C3861: 'SetupMatrices': identifier not found, even with argument-dependent lookup graphics.h(48) : error C2365: 'SetupMatrices' : redefinition; previous definition was a 'formerly unknown identifier' here is my render header file and graphics header file: #ifndef RENDER_H #define RENDER_H #include "header list.h" //----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render() { if( NULL == g_pd3dDevice ) return; // Clear the backbuffer to a blue color g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Setup the world, view, and projection matrices SetupMatrices(); // Render the vertex buffer contents g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 ); // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } #endif --------------------------------------------------------------------------- #ifndef GRAPHICS_H #define GRAPHICS_H #include "header list.h" //----------------------------------------------------------------------------- // Name: InitGeometry() // Desc: Creates the scene geometry //----------------------------------------------------------------------------- HRESULT InitGeometry() { // Initialize three vertices for rendering a triangle CUSTOMVERTEX g_Vertices[] = { { -1.0f,-1.0f, 0.0f, 0xffff0000, }, { 1.0f,-1.0f, 0.0f, 0xff0000ff, }, { 0.0f, 1.0f, 0.0f, 0xffffffff, }, }; // Create the vertex buffer. if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { return E_FAIL; } // Fill the vertex buffer. VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 ) ) ) return E_FAIL; memcpy( pVertices, g_Vertices, sizeof(g_Vertices) ); g_pVB->Unlock(); return S_OK; } //----------------------------------------------------------------------------- // Name: SetupMatrices() // Desc: Sets up the world, view, and projection transform matrices. //----------------------------------------------------------------------------- VOID SetupMatrices() { // For our world matrix, we will just rotate the object about the y-axis. D3DXMATRIXA16 matWorld; // Set up the rotation matrix to generate 1 full rotation (2*PI radians) // every 1000 ms. To avoid the loss of precision inherent in very high // floating point numbers, the system time is modulated by the rotation // period before conversion to a radian angle. UINT iTime = timeGetTime() % 1000; FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f; D3DXMatrixRotationY( &matWorld, fAngle ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set up our view matrix. A view matrix can be defined given an eye point, // a point to lookat, and a direction for which way is up. Here, we set the // eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction. D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f ); D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f ); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); // For the projection matrix, we set up a perspective transform (which // transforms geometry from 3D view space to 2D viewport space, with // a perspective divide making objects smaller in the distance). To build // a perpsective transform, we need the field of view (1/4 pi is common), // the aspect ratio, and the near and far clipping planes (which define at // what distances geometry should be no longer be rendered). D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); } #endif the only way I can fix the error is to #include "graphics.h" inside of "render.h".... I shouldn't have to though because I already included "header list.h" inside of "render.h" if you see something I don't, please reply

Share this post


Link to post
Share on other sites
this is whats happening
// h.h
#ifndef H_H
#define H_H

#include "a.h"
#include "b.h"

#endif

// a.h
#ifndef A_H
#define A_H

#include "h.h"

void callb(){b();}
void a(){};

#endif

// b.h
#ifndef B_H
#define B_H

#include "h.h"

void callb(){a();}
void b(){};

#endif

// m.cpp

#include "h.h"

int main()
{
calla();
return 0;
}


// step 1

#include "h.h"

int main()
{
calla();
return 0;
}

// step 2

#ifndef H_H
#define H_H

#include "a.h"
#include "b.h"

#endif

int main()
{
calla();
return 0;
}

// step 3

#ifndef H_H
#define H_H

#ifndef A_H
#define A_H

#include "h.h"

void callb(){b();}
void a(){};

#endif
#ifndef B_H
#define B_H

#include "h.h"

void callb(){a();}
void b(){};

#endif

#endif

int main()
{
calla();
return 0;
}

// step 4

#ifndef H_H
#define H_H

#ifndef A_H
#define A_H

#ifndef H_H
#endif

void callb(){b();}
void a(){};

#endif
#ifndef B_H
#define B_H

#ifndef H_H
#endif

void callb(){a();}
void b(){};

#endif

#endif

int main()
{
calla();
return 0;
}

// step 5

#ifndef H_H
#define H_H

#ifndef A_H
#define A_H

#ifndef H_H
#endif

void callb(){b();} // ERROR HERE!!! undefined
void a(){};

#endif
#ifndef B_H
#define B_H

#ifndef H_H
#endif

void callb(){a();}
void b(){};

#endif

#endif

int main()
{
calla();
return 0;
}

Share this post


Link to post
Share on other sites
Whether or not you want to hear about your organization, it is likely causing the problem. With the exception of class members, defining functions in headers is a very bad idea. The only reason you can (almost) get away with it now, if I understand your situation correctly, is that you only have one .cpp file. Declare the function in the header, then define it in a .cpp file. The errors you got probably result from either 1) not including the appropriate header in the file with WinMain() in it or 2) not including the .cpp file in your project. It is not enough to simply create it, you must add it to the list of project files, as well.

Learning to properly organize multi-file projects does take some effort, but the long term benefits in terms of avoided linker errors and what-not are tremendous. I can't be sure if your poor organization is what is causing your problem yet, but certainly no one wants to try to debug what is obviously some sort of file organization issue when the organization is so messy.

Share this post


Link to post
Share on other sites


Ok. I put all of my function declarations into .h files and all of the function bodies into .cpp files. I'm still getting an error stating that the functions are not declared. I use one header file "header list.h" to contain every other .h file in it. I include "header list.h" in every .h and .cpp file.
All of my .cpp files are included into my project folder. What else could I be doing wrong?

Share this post


Link to post
Share on other sites
ok. I got rid of the error saying that the functions were undeclared, but now I get linker errors:

graphics.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * g_pVB" (?g_pVB@@3PAUIDirect3DVertexBuffer9@@A) already defined in DX9 init.obj

graphics.obj : error LNK2005: "struct IDirect3DDevice9 * g_pd3dDevice" (?g_pd3dDevice@@3PAUIDirect3DDevice9@@A) already defined in DX9 init.obj

graphics.obj : error LNK2005: "struct IDirect3D9 * g_pD3D" (?g_pD3D@@3PAUIDirect3D9@@A) already defined in DX9 init.obj

render.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * g_pVB" (?g_pVB@@3PAUIDirect3DVertexBuffer9@@A) already defined in DX9 init.obj

render.obj : error LNK2005: "struct IDirect3DDevice9 * g_pd3dDevice" (?g_pd3dDevice@@3PAUIDirect3DDevice9@@A) already defined in DX9 init.obj

render.obj : error LNK2005: "struct IDirect3D9 * g_pD3D" (?g_pD3D@@3PAUIDirect3D9@@A) already defined in DX9 init.obj

D3D init crap.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * g_pVB" (?g_pVB@@3PAUIDirect3DVertexBuffer9@@A) already defined in DX9 init.obj

D3D init crap.obj : error LNK2005: "struct IDirect3DDevice9 * g_pd3dDevice" (?g_pd3dDevice@@3PAUIDirect3DDevice9@@A) already defined in DX9 init.obj

D3D init crap.obj : error LNK2005: "struct IDirect3D9 * g_pD3D" (?g_pD3D@@3PAUIDirect3D9@@A) already defined in DX9 init.obj

Debug/D3D init crap.exe : fatal error LNK1169: one or more multiply defined symbols found



GAHHHHHHHHHHHHHHH

Share this post


Link to post
Share on other sites
Quote:
Original post by CreepingDeath666
ok. I got rid of the error saying that the functions were undeclared, but now I get linker errors:

graphics.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * g_pVB" (?g_pVB@@3PAUIDirect3DVertexBuffer9@@A) already defined in DX9 init.obj


This is because you are declaring these variable in your header files, so every cpp file creates a new one.

I'm sure you're going to take this the wrong way, but you need to go through some C++ tutorials or get yourself a good book on the subject before you tackle something like DirectX.

Share this post


Link to post
Share on other sites

This topic is 4691 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