| | |
compiling multiple files using visual c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
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?
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?
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.
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.
![]() |
Similar Threads
- parsing multiple files in current directory (Perl)
- read multiple files (VB.NET)
- reading multiple files in loop (C++)
- Compiling Multiple files in a single Project (C)
- Multiple files (C)
- Copying multiple files with Visual Basic (Visual Basic 4 / 5 / 6)
- problems writing multiple files (Perl)
- How to Rename Multiple Files with Windows Explorer (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Give me the explanation for this output
- Next Thread: help please
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






