Including .cpp files using .Net

Started by
5 comments, last by Bljashinsky 19 years, 8 months ago
I know that this answer will be very simplistic, but don't think of me as a newbie. I have been programming for about a year now and I am working on a 3D horror game right now, but I have never learned how to do this. I am all self taught so I guess my books must have not covered this. I always included my .cpp files the same way I included my header files with #include. I was showing my code to someone and they couldn't believe I was doing that. So I tried fixing it, but couldn't find a place on the net detailing how to. I am using Visual C++.Net 2003. How do I include .cpp files? Thank you.
------------------------------------------------Please visit New World Video GamesPlease visit New World Video Game's Forums
Advertisement
All you do is add them to your project. Note that all functions must be prototyped in the file in which they are called and all variables outside the file in which they are used must be declared in that file using the "extern" keyword.
I don't know about 2003, but in 2005 edition it's just Project->Add Existing Item (Ctrl+shift+a), then select the headers and CPPs you want in it. When you compile each cpp will become an obj and then the obj's will be linked together into the exe/dll/lib. The way you're doing it just makes one big obj.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
OMFG! How many cpp files did you have? It would have had to rebuild all of them EVERY time! Not many I hope.

I think you just right click in the workspace view where there is the folder holding the files, or on the project icon and select "add files" from the menu. You'll find it.

btw, don't be afraid to ask these kind of things :-)
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Each C++ file in a IDE's project is compiled using a makefile into an .o file, which contains information about functions that are still to be linked as well as code and variable locations. The linker resolves all these dangling references and generates a .exe or .com etc.

make (or Visual C++'s version of make) checks whether the file has been modified, and then compiles it into an .o

Header files are there just so the compiler knows the signature of the function (C++ is particularly fussy about pre-declaration of functions, and for good reason) and to provide an easy place of documentation for the .cpp file, but they are not compiled.
Thank you for the help. I finally got it to work. I only had 7 .cpp files so it wasn't that bad.
------------------------------------------------Please visit New World Video GamesPlease visit New World Video Game's Forums
I hope I can ask this question in this same thread, because I feel it most likely relates. So I finally got my program to separate the files into different objects, but now I am getting 19 linking errors. Can anyone help explain these to me? Thank you for your help and for helping me out with my previous topics.

------ Build started: Project: Horror Project, Configuration: Debug Win32 ------Compiling...Direct3DSource.cppGenerating Code...Compiling...Terrain Functions.cppc:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(315) : warning C4018: '<' : signed/unsigned mismatchc:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(317) : warning C4018: '<' : signed/unsigned mismatchc:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(342) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(343) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(344) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(347) : warning C4244: 'argument' : conversion from 'int' to 'FLOAT', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(348) : warning C4244: 'argument' : conversion from 'int' to 'FLOAT', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(380) : warning C4267: 'argument' : conversion from 'size_t' to 'std::streamsize', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(387) : warning C4018: '<' : signed/unsigned mismatchc:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(416) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(416) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(416) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(417) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(417) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(417) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(418) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(418) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(418) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(419) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(419) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of datac:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(419) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of dataGenerating Code...Linking...Camera Method.obj : error LNK2019: unresolved external symbol _D3DXVec3TransformCoord@12 referenced in function "public: void __thiscall Camera::pitch(float)" (?pitch@Camera@@QAEXM@Z)Camera Method.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationAxis@12 referenced in function "public: void __thiscall Camera::pitch(float)" (?pitch@Camera@@QAEXM@Z)Camera Method.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "public: void __thiscall Camera::yaw(float)" (?yaw@Camera@@QAEXM@Z)Camera Method.obj : error LNK2019: unresolved external symbol _D3DXVec3Normalize@8 referenced in function "public: void __thiscall Camera::getViewMatrix(struct D3DXMATRIX *)" (?getViewMatrix@Camera@@QAEXPAUD3DXMATRIX@@@Z)Terrain Functions.obj : error LNK2001: unresolved external symbol _D3DXVec3Normalize@8Terrain Functions.obj : error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileA@12 referenced in function "public: bool __thiscall Terrain::LoadTexture(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadTexture@Terrain@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)d3dUtility.obj : error LNK2001: unresolved external symbol _D3DXCreateTextureFromFileA@12Terrain Functions.obj : error LNK2019: unresolved external symbol _D3DXFilterTexture@16 referenced in function "public: bool __thiscall Terrain::GenTexture(struct D3DXVECTOR3 *)" (?GenTexture@Terrain@@QAE_NPAUD3DXVECTOR3@@@Z)Terrain Functions.obj : error LNK2019: unresolved external symbol _D3DXCreateTexture@32 referenced in function "public: bool __thiscall Terrain::GenTexture(struct D3DXVECTOR3 *)" (?GenTexture@Terrain@@QAE_NPAUD3DXVECTOR3@@@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "bool __cdecl d3d::InitD3D(struct HINSTANCE__ *,int,int,bool,enum _D3DDEVTYPE,struct IDirect3DDevice9 * *)" (?InitD3D@d3d@@YA_NPAUHINSTANCE__@@HH_NW4_D3DDEVTYPE@@PAPAUIDirect3DDevice9@@@Z)d3dUtility.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "int __cdecl d3d::EnterMsgLoop(bool (__cdecl*)(float))" (?EnterMsgLoop@d3d@@YAHP6A_NM@Z@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _D3DXMatrixTranslation@16 referenced in function "bool __cdecl d3d::DrawBasicScene(struct IDirect3DDevice9 *,float)" (?DrawBasicScene@d3d@@YA_NPAUIDirect3DDevice9@@M@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationX@8 referenced in function "bool __cdecl d3d::DrawBasicScene(struct IDirect3DDevice9 *,float)" (?DrawBasicScene@d3d@@YA_NPAUIDirect3DDevice9@@M@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _D3DXMatrixScaling@16 referenced in function "bool __cdecl d3d::DrawBasicScene(struct IDirect3DDevice9 *,float)" (?DrawBasicScene@d3d@@YA_NPAUIDirect3DDevice9@@M@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _D3DXCreateCylinder@32 referenced in function "bool __cdecl d3d::DrawBasicScene(struct IDirect3DDevice9 *,float)" (?DrawBasicScene@d3d@@YA_NPAUIDirect3DDevice9@@M@Z)d3dUtility.obj : error LNK2019: unresolved external symbol _D3DXMatrixMultiply@12 referenced in function "public: struct D3DXMATRIX __thiscall D3DXMATRIX::operator*(struct D3DXMATRIX const &)const " (??DD3DXMATRIX@@QBE?AU0@ABU0@@Z)Direct3DSource.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "bool __cdecl Setup(void)" (?Setup@@YA_NXZ)Direct3DSource.obj : error LNK2019: unresolved external symbol _D3DXCreateFontIndirect@12 referenced in function "bool __cdecl Setup(void)" (?Setup@@YA_NXZ)Debug/Horror Project.exe : fatal error LNK1120: 16 unresolved externalsBuild log was saved at "file://c:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Debug\BuildLog.htm"Horror Project - 19 error(s), 21 warning(s)---------------------- Done ----------------------    Build: 0 succeeded, 1 failed, 0 skipped


[Edited by - Bljashinsky on August 5, 2004 12:27:24 PM]
------------------------------------------------Please visit New World Video GamesPlease visit New World Video Game's Forums

This topic is closed to new replies.

Advertisement