0

first post and I'm pretty new to programming compared to most of you. I'm at a University and we have virtual linux machines that we usually code on and compile to. We've always had a command to instantly compile all programs in a file. Now I'm trying to be a big boy and use Visual Studio 2013 on my home computer. I'm having problem compiling. When I compile, it will only read through the main.cpp, even if I #include "blah.h" at the top. How do I set the compiler to check everything in my project.

I also don't get the point of the "build". I've never run across this before on our linux machines. We just write what we want, #include everything we use, and the compiler just reads it all and does it's job.

I'm a noob so don't judge. I am pretty good with all my knowledge, classes, pointers, data structures, I'm just a complete noob when it comes to compilers and IDEs. What is the difference in g++ compiler? My professor never talked much about IDEs and compilers aside from easy to use linux machine we have on campus.

TL;DR: How do I compile .hpp and .h in VS2013, always used easy peasy linux machine on campus.

2 Answers2

0

You have to set up a project: File -> New Project, Under Visual C++ pick General and then create an Empty Project. Assume it is called Test1. Then, head over to the Solution Explorer, right click on Test1 and under Add, there should be Add Existing Items. Add your files and you are good to go!

yizzlez
  • 8,757
  • 4
  • 29
  • 44
  • Yeah, I'm working on an ArrayList Data Structure now and it won't compile my .h and .hpp files. It just checks the main.cpp. How do I set the compiler to debug all of the files? – MartYMcFly Feb 21 '14 at 00:58
  • Yes, they're all in there. I have main.cpp, arraylist.h, arraylist.hpp. I've tried putting them in Source Files and in Header Files but it just wont compile them. It just compiles the main.cpp. – MartYMcFly Feb 21 '14 at 01:00
  • Try pressing F5, what happens – yizzlez Feb 21 '14 at 01:00
  • It runs my program, only the main.cpp. Say for example I purposely type an error in my .hpp, like putting a random "kill tom" on line 32, it will still run. It won't catch the error. – MartYMcFly Feb 21 '14 at 01:01
0

You might want to read this question:Do I need to compile the header files in a C program?

In short, there is no need to compile the .h files since these .h files shall be included in the .cpp files.

In order to check everything in your project, the .h file shall be included in you main.cpp. In this case, the visual studio compiler shall precompile the cpp file which means the #include "test.h" will be replaced by the content of test.h .

What is the difference in g++ compiler?

"GCC has special treatment for files with .h extension when they are supplied to the compiler as command-line arguments."

Community
  • 1
  • 1
Steve
  • 1,448
  • 11
  • 18
  • How do I know that my .h files all have proper syntax? How can I debug them? – MartYMcFly Feb 21 '14 at 03:19
  • Another thing, how do I compile my .hpp, the implementation for my header class. – MartYMcFly Feb 21 '14 at 03:20
  • @MartYMcFly, If the .h files are included in the .cpp file, MS compiler will check the syntax. In order to prove that you might implement some incorrect codes in .h file and include it in the .cpp file. The output window will print the false. – Steve Feb 21 '14 at 09:10
  • What does "print the false" mean, and whenever I purposefully put an error in my .h, it still compiled the main and ran it. – MartYMcFly Feb 22 '14 at 23:09
  • @MartYMcFly, sorry for the confusion. "print the false" means the false of .h file will be printed in the output window. I have tested in my PC, and the errors were printed correctly. – Steve Feb 24 '14 at 01:34
  • @MartYMcFly . It will help if you add more information of your code in you question. :) – Steve Feb 24 '14 at 01:34