When this thread started I fell off, I was too lost and did not have a clear motivation at the time.
Now I have motivation to continue with a bit of beginner programming in C, then I can later advance to C++. The reason to start in C is that I have found a small program that has given me a goal to try and see how far I can get, ie I am motivated
I have been reading lot in this area, have a lot of information in my head. just can't get it to come together. Let me get to the usual starting point, "hello world".
I have a directory set aside for this simple experiment.
[gert@localhost conly]$ ls -l
-rwxr-xr-x 1 gert gert 5564 Jan 22 15:51 ctest_hello*
-rw-r--r-- 1 gert gert 113 Jan 22 15:50 ctest_helloworld.c
The follwoing I took to mean I have C compiler?
[gert@localhost conly]$ gcc
gcc: no input files
Would probably have been a bit smarter trying to work out the version number with gcc -v
, whilst getting this it also looks a bit intimidating. Consulting gcc --help
reveals that the statement shows files called by gcc
[[root@localhost ~]# gcc -v
Using built-in specs.
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-slibdir=/lib --with-bugurl=https://pclinuxos.com/ --mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release --enable-languages=c,c++,ada,fortran,objc,obj-c++,java --build=i586-mandriva-linux-gnu --host=i586-mandriva-linux-gnu --with-cpu=generic --with-system-zlib --enable-threads=posix --enable-shared --enable-objc-gc --enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-22.214.171.124/jre --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-gtk-cairo --disable-libjava-multilib --enable-ssp --disable-libssp --disable-werror --with-python-dir=/lib/python2.6/site-packages --enable-lto --enable-plugins
Thread model: posix
gcc version 4.5.2 (GCC)
[root@localhost ~]# gcc -V
gcc: '-V' option must have argument
Got the version gcc version 4.5.2 (GCC)
and guessing upper case V did not do better. Leave it at that.
Copied content below from critter
s post in the nearby thread, as it was stated to be C code. I copied the text into kwrite and saved the file. Got a bit carried away with file names, I regret that as it is more typing
[gert@localhost conly]$ cat ctest_helloworld.c
printf("Hello PCLinuxOS user!"
" I like the number 9"
" for some reason.\n");
Then compiled as below
[gert@localhost conly]$ gcc ctest_helloworld.c -o ctest_hello
The file ctest_hello
shows up, and it is not text file, so assuming it is binary but not yet .exe or something.
Question, how can I run this file? Or is that the stage where one must go looking for makeEdit:
When I started on this exercise, I got the impression that to make a running program, as simple as this, all that was needed was the line something like, gcc ctest_helloworld.c -o ctest_hello
and that my exe file was the last filename.
I took a break because my head was spinning a bit too much, coming back I got the bright idea of search the Internet for: compiling c programs
from what I pick up I am on the right track.
I guess the next step is called debugging
nothing to do with makea.out
Reading through the section here I came across the a.out
where did that belong, another penny dropped
[gert@localhost conly]$ gcc ctest_helloworld.c #this produces the a.out file haaah this is where it comes from
Red portion above is probably the simplest form of a compile statement, the default file output is a.out
Could not help trying out the use of #
on the command line to annotate what is presently going on. The command line interpreter ignores what comes after the #.
In the mean time I remembered something old-polack
mentioned some time ago when apparently I must have been trying to run an exe file, you use ./
in front of the file to indicate run from present position
, even though you are already in the directory, ie my present position already is correct, that one beats me.
Well I will suggest the for a C program the "Hello World" is changed a bit, something like
[gert@localhost conly]$ ./a.outgcc and option -o
Hello PCLinuxOS user! when you have the result of the gcc xxxx.c to use ./<exefile_name> to start the program and by the way to use ctl-C to bail out
This option is used to specify a none default output file such as in my compile run gcc ctest_helloworld.c -o ctest_hello
the output file is ctest_hello
Well this was my warm up to a problem, which I now have to and find again. This other program have decided to play hide and seek. I will take a brake though as last time that gave beneficial result.