locked
compile and link c program in visual C++ 20008 Express

    Pergunta

  • My intention is to use Visual C++ 2008 Express to make small changes in valid c programs that I previously wrote (a while aog). I changed the name on one of these valid programs.  Then in order to test the compile, I loaded it in successfully (making no changes fromteh original program) and tried to compile (and link). 

     

    All I saw was a Build menu that seemed greyed out.  But it did have a drop down.  On the drop down was the word "Build." I clicked on it and all that heppened was a chekcmark that appeared next to the word.  There was nothing else that seemed to do anything.

     

    How do I compile and link a c program in Microsoft Visula C++ 2008 express?  Thanks in advance!

    The program has a .c extension.  Should it have another extension?

    sexta-feira, 3 de outubro de 2008 02:39

Todas as Respostas

  • Create a project first.
    sexta-feira, 3 de outubro de 2008 03:07
    Moderador
  • Thanks -- that advice was certainly helpful, simple though it was.

    However, I clicked on New > Project from Existing Code, and when the program asked "What type of project would you like to create?" the only option was C++.

    Do I need to rename my c file? Or what?

    sexta-feira, 3 de outubro de 2008 05:41
  • Double-click the .cpp that was generated for you and paste your 'C' code into it.  You want to keep the #include stdafx.h statement.  Build.  If you get compile errors because you use 'C' specific syntax that the C++ compiler doesn't like, right-click the .cpp file and rename it to .c
    sexta-feira, 3 de outubro de 2008 10:12
    Moderador
  • Windows Vista may be my problem.  I decdied to try Cygwin with gcc. If that doesn't work I'll go back to Visual Studio, though it's not working yet. I'm sure I'll lget thsi straightened out somehow.

    Thanks.


    segunda-feira, 6 de outubro de 2008 02:55
  • I tried this on Vistual Studio Team System 2008 version. Please see if the following steps works for explorer version too:
    1. Open Visual Studio. From the menu bar select File -> New -> Project.
    2. New project window will pop-up. There will be multiple project types. Search for Visual C++ (mine was under other languages) and select Win32 under Visual C++.
    3. Select Win32 console application from the templates pane.
    4. Enter the name for your project. Click "Next" button.
    5. A new pop-up window titled "Win32 Application Wizard - <your project name>" will show up. <your project name> is the name you gave to your project in the previous step. Click "Next" button.
    6. You should see "Application settings" in the popup window. Make sure that "console application" is checked under application type.
    7. This is important step: Under additional options, UNCHECK "Precompiled header" and CHECK "Empty project".
    8. Your project should be created by now (if everything went correctly). You should see 3 folders in your project -- header files, resource files and source files. If solution explorer is not visible, you can make it visible by selecting View -> Solution Explorer from the menu bar.
    9. Right click on the "source files" folder from solution explorer. Select Add -> New item. 
    10. You will see "Add new item" popup window. From categories pane on the left, select "Code" under "Visual C++".
    11. From the "templates" pane on the right, select C++ file. (Don't worry! see below)
    12. This is important step: Create the name of the file with ".c" extension. For e.g., Program.c. Click "Add" button.
    13. If the file is successfully added, you will see the name of the file under "source files" in solution explorer.
    14. Double click the file you added from solution explorer. Type in your C code. Save the file.
    15. From menubar, select View -> Output
    16. From solution explorer, right click on the solution name and select "Build solution" to compile your project.
    17. The output of the build will be displayed in the "output window" you opened in step 15. The very last line should be something like "1 succeeded, 0 failed, 0 skipped". This means, build was successful.
     18. In your source code, right click on the very last curly brace and select Breakpoint -> Insert Breakpoint. You will see a solid red circle next to the curly brace indicating that the breakpoint is set.
    19. From solution explorer, right click on the project (not the solution -- the project will be just below the solution) and select Debug -> Start new instance.
    20. Your program will execute until the breakpoint and stop there. A console window will be opened (but it may have been minimized. Check your minimized windows). You can verify that whatever printfs you issued in your program appeared in this console window.
    21. Select Debug -> Continue from the menu bar. You should see from the output window something like (xxx has exited with code 0. 0x0). This means your program ran normally.

    Notes 1:
    The main function should always be declared as
    (a) int main(void)
    or
    (b) int main(int argc, char *argv[0])
    Don't forget to insert "return 0" at the end of the program, as you declared "main" returning an "int".
    Corollary to this is "void main()" or "main()" are not C standard and known to give problems.

     Note 2:
    Adding multiple source files to your project is easy - right click on "source files" folder in solution explorer. select "Add -> New item" or "Add -> Existing item".

    Note 3:
    It's been a while since I used explorer edition. If you don't see option to create new project under "File" menu, check under "Project" menu.


    Note 4:
    #includ e<stdio.h> worked for me. In case you see problems, try #include <stdlib.h>

    Hope this helps
    • Sugerido como Resposta KKRangan quarta-feira, 25 de março de 2009 06:08
    quarta-feira, 25 de março de 2009 06:08
  • I tried this on Vistual Studio Team System 2008 version. Please see if the following steps works for explorer version too:
    1. Open Visual Studio. From the menu bar select File -> New -> Project.
    2. New project window will pop-up. There will be multiple project types. Search for Visual C++ (mine was under other languages) and select Win32 under Visual C++.
    3. Select Win32 console application from the templates pane.
    4. Enter the name for your project. Click "Next" button.
    5. A new pop-up window titled "Win32 Application Wizard - <your project name>" will show up. <your project name> is the name you gave to your project in the previous step. Click "Next" button.
    6. You should see "Application settings" in the popup window. Make sure that "console application" is checked under application type.
    7. This is important step: Under additional options, UNCHECK "Precompiled header" and CHECK "Empty project".
    8. Your project should be created by now (if everything went correctly). You should see 3 folders in your project -- header files, resource files and source files. If solution explorer is not visible, you can make it visible by selecting View -> Solution Explorer from the menu bar.
    9. Right click on the "source files" folder from solution explorer. Select Add -> New item. 
    10. You will see "Add new item" popup window. From categories pane on the left, select "Code" under "Visual C++".
    11. From the "templates" pane on the right, select C++ file. (Don't worry! see below)
    12. This is important step: Create the name of the file with ".c" extension. For e.g., Program.c. Click "Add" button.
    13. If the file is successfully added, you will see the name of the file under "source files" in solution explorer.
    14. Double click the file you added from solution explorer. Type in your C code. Save the file.
    15. From menubar, select View -> Output
    16. From solution explorer, right click on the solution name and select "Build solution" to compile your project.
    17. The output of the build will be displayed in the "output window" you opened in step 15. The very last line should be something like "1 succeeded, 0 failed, 0 skipped". This means, build was successful.
     18. In your source code, right click on the very last curly brace and select Breakpoint -> Insert Breakpoint. You will see a solid red circle next to the curly brace indicating that the breakpoint is set.
    19. From solution explorer, right click on the project (not the solution -- the project will be just below the solution) and select Debug -> Start new instance.
    20. Your program will execute until the breakpoint and stop there. A console window will be opened (but it may have been minimized. Check your minimized windows). You can verify that whatever printfs you issued in your program appeared in this console window.
    21. Select Debug -> Continue from the menu bar. You should see from the output window something like (xxx has exited with code 0. 0x0). This means your program ran normally.

    Notes 1:
    The main function should always be declared as
    (a) int main(void)
    or
    (b) int main(int argc, char *argv[0])
    Don't forget to insert "return 0" at the end of the program, as you declared "main" returning an "int".
    Corollary to this is "void main()" or "main()" are not C standard and known to give problems.

     Note 2:
    Adding multiple source files to your project is easy - right click on "source files" folder in solution explorer. select "Add -> New item" or "Add -> Existing item".

    Note 3:
    It's been a while since I used explorer edition. If you don't see option to create new project under "File" menu, check under "Project" menu.


    Note 4:
    #includ e<stdio.h> worked for me. In case you see problems, try #include <stdlib.h>

    Hope this helps

    OMG!!! I LOVE U SOO MUCH!!! just saved so much hassle..i'm kinda new to C++ ( i have done some java)..n everytime i created a simple math program, the program would open n close for a second...n then it wouldnt compile because i didnt know about the built-in headers that are preloaded...sweet..now i can continue on my dream of making a new xbox game...thnx a LOT!!! :) :)
    segunda-feira, 3 de agosto de 2009 18:28
  • Visual C++ 2008 express is able to compile C, just create a project and replace the C++ file with your C file. That should work.
    terça-feira, 11 de agosto de 2009 19:34
  • Your instructions worked the first time I used it to write a program in C++ using Visual C++. Thanks a lot for taking the time to write out the instructions.

    domingo, 27 de setembro de 2009 17:57
  • Sounded good... KKRangan... I am working with Express 2010. Still, no luck. 3 days and I still cannot compile and run something as simple as 'Hello World.' Getting the Help file to work on either online or local help is also a disaster and finding help on anything that actually helps these issues is a lost cause.

    There has to be something criminal about making it impossible to find help on getting help!!!!

    Ever feel as if you just wasted 3 solid days of your life? Thanks Microsoft. Next time you release something, don't make it so difficult to find some help. I challenge you to put someone who knows nothing about your website or a given program they are having trouble with to find help on an issue in a REASONABLE amount of time without... well... help. It's spaghetti. Frustrating. Enraging.

    I guess I'll go find a compiler that really WORKS and has working HELP and SUPPORT.
    quinta-feira, 13 de maio de 2010 01:51
  • Hi Silver_Mane,

    I am sorry to hear that you are facing issues. Are you trying to compile C++ program or C program? I notice that there are 3 different express editions - one for VB, one for C# and one for C++. I don't know VB, so I can't help you there. I am quite familiar with C/C++ and reasonably with C#. Can you please provide more details regarding what you were trying to do? I haven't used VS 2010 but I can try it out and let you know.

    Regards,

    KKRangan

    quinta-feira, 13 de maio de 2010 04:17
  • I just created a C program and compiled using VS 2010 Express edition (using exact same steps like the one I mentioned for 2008) and it worked as expected.

    Also, when you created a windows 32 console C++ application and build it, it should compile straigt away (in case you are not interested in compiling C programs but just C++ ones). Please let me know if you still have issues.

     

    quinta-feira, 13 de maio de 2010 04:47
  • I am very new to programming and barely know the jargon. I have been using on line tutorials and started with VC++2010. KKRangans advice above was excellent but once in the work space or (Global Scope) where you actually write the program I cant even get the most simple 'Hello World' program to work. It comes up with-  fatal error C1003: error count exceeds 100;  The program is exactly the same as in all the tutorials and I even added the Notes 1 a & b in KK Rangans advice above but same error comes up. I have spent 2 days now trying to demystify the compiler. Its not even obvious where the 'hello World' result is even supposed to appear, does another frame appear? does it appear in Command Window at the bottom? The output just seems to show error, is that where the 'hello world' words would appear if there was no error??? Who knows? The help file is useless. No easy access to a manual in the help- I mean, could it get any more user unfreindly!!

    segunda-feira, 24 de maio de 2010 01:07
  • hi there,

    I am somewhat new to Vc++.

    Thanks for te steps.Saved a lot of time.

    Prior to reading this i missed the breakkpoint at end of brackets.

    Thanks again

     

    sexta-feira, 16 de julho de 2010 05:22
  • I decided to learn the basics of C prior to learning C++. I have heard that Visual C++ is a great IDE for C++. I too was wondering how to program/build C project in Visual C++.

     

    Thank you KKRangan. Your instructions work perfectly in Visual C++ 2010 Express Edition.

    domingo, 5 de setembro de 2010 01:40
  • Thank you so much. It worked perfectly for visual studio 2010.
    domingo, 16 de outubro de 2011 00:52
  • I have ample exposure to Linux based software development. For Visual Studion 2008 I was having starting trouble. Your post was helped me to get going in two minutes.

    Thanks a lot for sharing this.

    Regards,

    DR

    segunda-feira, 16 de janeiro de 2012 10:11
  • Hello,KKRangan.

    I'm a beginner of C programing language. It's my first time to use MS Vistual C++ 2010. Lucky to find your post, I followed your steps carefully and the program produced the result. See the picture below.

    Although it produced the text  "The program '[6004] big.exe: Native' has exited with code 0 (0x0).", I still wondered whether it was wrong. Please help me. Many thanks.

    quinta-feira, 23 de fevereiro de 2012 11:15
  •  sir , this information is useful to me.... thank sir...

    domingo, 11 de março de 2012 04:51
  • Although it produced the text "The program '[6004] big.exe: Native' has exited with code 0 (0x0).", I still wondered whether it was wrong. Please help me. Many thanks.
    The output you show is normal. Your program worked correctly.
     

    David Wilkinson | Visual C++ MVP
    domingo, 11 de março de 2012 12:06
  • I tried to  compile c progrqam in Visual C++ 2010.

    I created project as you said above. I am able to create the file in .c but after build it is displaying following error.

    Unable to start the program hello.exe the system cannot find the file specified.

    Could you help me on this.

    Thanks:)

     
    quinta-feira, 1 de novembro de 2012 18:21