Sign in to follow this  
Bljashinsky

Including .cpp files using .Net

Recommended Posts

Bljashinsky    127
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.

Share this post


Link to post
Share on other sites
Holy Fuzz    213
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
iMalc    2466
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 :-)

Share this post


Link to post
Share on other sites
CloudNine    224
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.

Share this post


Link to post
Share on other sites
Bljashinsky    127
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.cpp
Generating Code...
Compiling...
Terrain Functions.cpp
c:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(315) : warning C4018: '<' : signed/unsigned mismatch
c:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(317) : warning C4018: '<' : signed/unsigned mismatch
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\My programs\C++\DirectX Games\Horror Source Code\Terrain Source\Horror Project\Terrain Functions.cpp(387) : warning C4018: '<' : signed/unsigned mismatch
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
c:\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 data
Generating 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@8
Terrain 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@12
Terrain 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 externals

Build 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]

Share this post


Link to post
Share on other sites

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