0.7 — A few common C++ problems
In this section, we’ll address some of the common issues that new programmers seem to run across with fairly high probability. This is not meant to be a comprehensive list of compilation or execution problems, but rather a pragmatic list of solutions to very basic issues. If you have any suggestions for other issues that might be added to this list, post them in the comments section below.
|
Answer 5: Debug it! You can find information on how to debug programs in lesson 1, specifically sections 1.11 -- Debugging your program (stepping and breakpoints) and 1.11a -- Debugging your program (watching variables and the call stack).
|
|
Answer 6: Go to the Tools Menu, and choose Options. Under the Text Editor submenu, choose All Languages (or C/C++), and you’ll see a checkbox on the right for Line numbers.
|
Problem 7: When I compile my program in Visual Studio 2010, I get an error message about a COFF file being invalid. How do I fix this?
Answer 7: If you see the following error when compiling with Visual Studio 2010:
You’ve encountered a Microsoft OS/compiler incompatibility. It has nothing to do with your code.
The best first option is to download and install Visual Studio 2010 Service Pack 1.
If that does not fix your issue, there are many other good suggestions on this Stack Overflow thread about the various causes and solutions to this problem.
|
Problem 8: When I compile my program, I get an error about unresolved external symbol _main or _WinMain@16
Answer 8: This means your compiler can’t find your main() function. All programs must include a main() function.
There are a few things to check:
a) Does your code include a function named main? b) Is main spelled correctly? c) Is the file containing main part of your project? (if not, either move the main function to one that is, or add the file to your project. See lesson 1.8 -- Programs with multiple files for more information about how to do this). d) Is the file containing function main set to compile? (Also see lesson 1.8 -- Programs with multiple files for more information about how to do this). |
|
Answer 9: This is a warning, not an error, so it shouldn’t impact your program working. However, it is annoying. To fix it, go into the Debug menu -> Options and Settings -> Symbols, and check “Microsoft Symbol Server”.
|
Problem 10: I’m using Code::Blocks or g++ on the command line, and none of the C++11 functionality works
Answer 10: For Code::Blocks, go to Project->Build options->Compiler settings->Compiler flags and check “Have g++ follow C++11 ISO C++ language standard”
See lesson 0.5 -- Installing an Integrated Development Environment (IDE) for pictures of how to do this.
For compiling with g++ on the command line, add the following to the command line:
-std=c++11 |
|
Answer 12: Your virus scanner may be blocking execution. Try disabling it temporarily and see if that’s the issue.
|
I have some other problem that I can’t figure out. How can I get an answer quickly?
As you progress through the material, you’ll undoubtedly have questions or run into unexpected problems. What to do next depends on your problem. But in general, there are a few things you can try.
First, ask Google. Find a good way to phrase your question and do a Google search. If you have received an error message, paste the exact message into google using quotes.
Odds are someone has already asked the same question and there is an answer waiting for you.
Odds are someone has already asked the same question and there is an answer waiting for you.
If that fails, ask on a Q&A board. There are websites designed for programming questions and answers, like Stack Overflow. Try posting your question there. Remember to be thorough about what your problem is, and include all relevant information like what OS you’re on and what IDE you’re using.
No comments:
Post a Comment
whatiscpp.blogspot.com is a free website devoted to teaching you how to program in C++. Whether you’ve had any prior programming experience or not, the tutorials on this site will walk you through all the steps to write, compile, and debug your C++ programs, all with plenty of examples.