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

## Recommended Posts

##### Share on other sites

I didn't ask for commentary about my organization, I asked if anyone could help me figure out why I was getting the errors.

##### Share on other sites
The reason why I put the functions' bodies inside of the .h files is because when I put them into .cpp files, I would get errors saying that the functions were undeclared when I try to call them in my winmain function

##### 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"#endifint 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#endifint main(){	calla();	return 0;}// step 4#ifndef H_H#define H_H#ifndef A_H#define A_H#ifndef H_H#endifvoid callb(){b();}void a(){};#endif#ifndef B_H#define B_H#ifndef H_H#endifvoid callb(){a();}void b(){};#endif#endifint main(){	calla();	return 0;}// step 5#ifndef H_H#define H_H#ifndef A_H#define A_H#ifndef H_H#endifvoid callb(){b();} // ERROR HERE!!! undefinedvoid a(){};#endif#ifndef B_H#define B_H#ifndef H_H#endifvoid callb(){a();}void b(){};#endif#endifint main(){	calla();	return 0;}

##### 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 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 on other sites
Quote:
 I include "header list.h" in every .h and .cpp file.

including header list.h in all .h files may be the problem
try removing

##### Share on other sites

ummm...from which file? because every one of my .h files needs the header files located in "header list.h"

##### Share on other sites
Quote:
 because every one of my .h files needs the header files located in "header list.h"

##### 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 on other sites
try cleaning the project

##### Share on other sites

cleared it. didn't work. this sucks. I looked in my DX9 init files and no where in them are the definitions of the functions I am getting linker errors for.

##### Share on other sites
Quote:
 Original post by CreepingDeath666ok. 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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628711
• Total Posts
2984341

• 23
• 11
• 10
• 13
• 14