944,117 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 707
  • C++ RSS
Nov 3rd, 2009
0

compiling multiple files using visual c++

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blackst0rm is offline Offline
1 posts
since Nov 2009
Nov 3rd, 2009
-7
Re: compiling multiple files using visual c++
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; Nov 3rd, 2009 at 11:19 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Give me the explanation for this output
Next Thread in C++ Forum Timeline: help please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC