Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Getting your C++ program to run

Here are some problems with compiling and running a quite straightforward C plus plus program (Gnu C++ compile gcc)

wizard:cpp graham$ g++ morethan.cpp
morethan.cpp:9:18: error: ir.inc: No such file or directory
morethan.cpp: In function   [82][ac][cb]Üint main()  [82][ac] Ä :
morethan.cpp:27: error:   [82][ac][cb]Üintread  [82][ac] Ä  was not declared in this scope


What happened? An "include" file was missing ... it couldn't be found (first error), nor could symbols that were defined in it (second error)
Solution: Copy the include file into the current directory (have you only downloaded part of an application?)

wizard:cpp graham$ g++ morethan.cpp
Undefined symbols:
  "intread(char const*)", referenced from:
      _main in ccOOqa9r.o
      _main in ccOOqa9r.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


What happened? The compile worked, but then you failed to link the compiler output to all the other components needed to make up an application.
Solution: Add the name of the other files that make up the application onto the compile / load command
OR Solution: Specify just compile (-c option) not compile and load (default)

wizard:cpp graham$ g++ morethan.cpp ir.cpp
wizard:cpp graham$


What happened? It worked ... "no news is good news" BUT where it the output file (the program)
Solution: It's in a file called a.out - that's the [very curious] default

wizard:cpp graham$ a.out
-bash: a.out: command not found


What happened? Your PATH doesn't include the current directory, so when you tried to run a.out it didn't look in the right place for it
Solution: Add current directory to PATH (but be aware of security issues)

wizard:cpp graham$ ./a.out
Enter year of first book 2006
Enter year of second book 2004
First book is newer
Age difference is 2
first book: 2006
second book: 2004


What happened? It worked!

wizard:cpp graham$ g++ -o moreisless morethan.cpp ir.cpp
wizard:cpp graham$


What happened? Compile, link / load and the output file is named this time

wizard:cpp graham$ ./moreisless
Enter year of first book 2010
Enter year of second book 2011
First book is older
Age difference is 1
first book: 2010
second book: 2011


What happened? It worked!

The source code used in this example can be found in our Introduction to C++ resource bundle
(written 2010-11-15, updated 2010-11-16)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C231 - C and C based languages - Introduction to C++
  [317] Programming languages - a comparison - (2005-05-20)
  [318] Choosing a theme - (2005-05-20)
  [336] Targetted Advertising - (2005-06-05)
  [928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
  [2004] Variable Scope in C++ - (2009-01-22)
  [2169] When should I use OO techniques? - (2009-05-11)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [4466] Moving from C to C++ - Structured to Object Oriented - a lesson for engineers - (2015-03-28)
  [4561] Hello World in C++ - a first program, with the process explained - (2015-10-30)
  [4562] Left shift operator on an output stream object - C++ - (2015-10-30)

C051 - C and C based languages - C++ - General
  [2370] C++, Python, and other training - do we use an IDE - (2009-08-21)
  [2504] Learning to program in ... - (2009-11-15)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2577] Complete teaching example - C++, inheritance, polymorphism - (2010-01-15)
  [2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
  [2851] Further C++ material - view new or old - (2010-07-04)
  [3067] Using C and C++ functions in the same program - how to do it - (2010-11-24)
  [3129] Extra courses - C and C++ - (2011-01-12)
  [3155] Rake - a build system using code written in Ruby - (2011-02-03)
  [3587] C++ Courses - do I get official certification at the end of my Well House course? - (2012-01-20)
  [3809] Dwarf Exception Unwind Info - (2012-07-20)
  [4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++ - (2014-11-30)
  [4355] C++ in 2 days - (2014-12-18)


Back to
Positively reforming the system - could it be done?
Previous and next
or
Horse's mouth home
Forward to
Make - automating the commands for building and installing
Some other Articles
C++ - a complete example with polymorphism, and how to split it into project files
Zyliana Kyrei Cox
Longhope Hotel
Getting your C++ program to run
Positively reforming the system - could it be done?
Views of Melksham - November 2010
Computer Graphics is fun - even if Java Applets are Old Hat
String handling - from first steps to practical examples
What is a universal superclass? Java / Perl / Python / Other OO languages
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3052_Get ... o-run.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb