compiling multiple files using visual c++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 1
Reputation: blackst0rm is an unknown quantity at this point 
Solved Threads: 0
blackst0rm blackst0rm is offline Offline
Newbie Poster

compiling multiple files using visual c++

 
0
  #1
19 Days Ago
I am using Visual C++ Express Edition.
I have 3 files: (A) main.cpp, (B) prototypes.h (C) implementation.cpp.
main.cpp includes prototypes.h and prototypes.h includes implementation.cpp. When I go to "Start without debugging" things screw up because in (C) implementation.cpp the compiler complains that it can't find the data fields. e.g. it's not properly connecting with the .h file. How do I fix this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,340
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
0
  #2
19 Days Ago
Step 1: Create a console project. File --> New --> Project. Project types: select Win32. Templates: select "Win32 Console Application". Near the bottom of the screen enter a project name and location. Then press Ok button.

Step 2: On this window just click Next

Step 3: Application Settings window: Uncheck the Precompiled Headers setting. That is very useful for complex programs with lots of files, but not for simple programs. Click Finish button.

Step 4: You will see a starter _tmain() function. I would just delete that code. You will also want to change the project settings so that the compiler does not attempt to compile for UNICODE. To do that, select Project --> <project> Properties (at the bottom of the menu), expand the Configuration Properties menu, select General. On the right side of the screen change "Character Set" to "Not Set".

Step 5: copy the two *.cpp and *.h files into the project folder so that they can be used in the project. This step would have been unnecessary had you created the project when you first started.

Now you are ready to add your files to the project.
In Solution Explorer (left side of the screen) right-click the folder named "Source Files". A drop-down men appears, and you want to select the very first one that says "Add". That will give you another popup menu, and select the second menu item that says "Existing Item". This will give you a dialog box where you can select the main.cpp and implementation.cpp. You can select them both or just one at a time. After you highlighted (selected) the file(s) press the Add button at the bottom of the dialog box.

Now you have to edit prototypes.h to remove the [icode]#include "implementation.cpp" [icode] line. You never ever want to include *.cpp files in header files. Its always the other way around. Now edit implementation.cpp and add [icode]#inlcude "impleentation.h" near the top of the file.

Now you are ready to compile the program. Since both *.cpp files are now part of the project the compiler will compile each *.cpp file individually and link them together to create a single executable program.
Last edited by Ancient Dragon; 19 Days Ago at 11:19 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC