Learning C - I nobbled Geany

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Learning C - I nobbled Geany

Post by cobaka »

Hello all, woof!
Specs for my environment are below my signature.

I am learning the C programming language.
I am a novice.
Yesterday I could compile, build and execute a program within Geany. I used the icons provided to do this.
compile, build, run. When I used the function keys to do the same thing - all worked as expected.
By this I mean I when I clicked the 'execute' gear icon a second terminal window would open. The compiled program ran.

Now, (today) this does not happen. In some way I have nobbled Geany.
I did open edit > preferences > but took care in what I did (or so I thought).
I the execute button no longer opens a terminal window.

However - outside, opening the terminal from the desktop - the compiled code runs.
I compile the source; I can run the binary: eg # ./hello // the pwd for the terminal is the directory where the source is found.
or # ./calc_hypoten
In some way I have nobbled Geany
What have I done?
My suspicion. I ran a file called 'make'. Maybe that nobbled the process.

Help appreciated.

Cobaka

environment is: uPupBB 19.03 on i3 CPU. Geany 1.29 (supplied with uPup)
Everything else is standard. Got the C compiler from the uPupBB repository.
It compiled/ran a few days ago. Tnx everyone.
In ' build' the command is: "./%e"

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: Learning C - I nobbled Geany

Post by snoring_cat »

Please verify your build commands, and compiler messages. (Below are some reference images).

Example helloworld.c code

Code: Select all

#include <stdio.h>

int main(int argc, char **argv)
{
	printf("hello world\n");
	return 0;
}

Save this file as helloworld.c, and then hit F9, or hit the build button. Geany will create "helloworld" in the same folder as "helloworld.c". Hit F5, or the execute/run button to test out the newly created executable. If that works correctly, then you can then test out your Makefiles, etc.

[Note: Please make sure that the active tab is the C file. For a bad example, note that if you have a .html file opened, and it is the currently active tab, Geany will try to compile the .html file.]

build_commands_menu.png
build_commands_menu.png (171.92 KiB) Viewed 899 times
message_window.png
message_window.png (67.7 KiB) Viewed 899 times

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

Thank you, @snoring_cat

Followed your instruction. Nada. Can edit/compile/build program. I ran the program using a terminal window (I saw expected result).
Below, you will see the config files but I have one more observation. I read the last line in your posting.
I remembered something. One of the last things I did before the problem arose was to edit and "run" some html.
The code was called 'page.html' I did this while I following a tutorial on you-tube about using geany.
Now, (5 minutes ago) I opened that html code and hit "F5". Light (browser) opened and I saw the web-page I made.
So the html "code" ran, but my C code does not. Using ROX I see the source: "hello_world.c". I see corresponding object code and executable file.
I suspect I have some-how switched the active something (I don't know what) - but I suspect you gave me a hint in your last para.
Here is my 'build' config. My working directory is: /mnt/sda2/bThings/Computing/C/tut/ (but I think this is irrelevant in this context)
Tnx for ur help.

Hello_cat.jpg
Hello_cat.jpg (65.8 KiB) Viewed 894 times

cobaka

I see this when I use the terminal to run hello_world.

# cd /mnt/sda2/bThings/Computing/C/tut;pwd
/mnt/sda2/bThings/Computing/C/tut
# ./hello_world
hello world
# ./hello_world
hello world
# ./hello_world
hello world
#

This proves that the compilation is OK, the object code is ok and executable.
I can post a window showing ROX if that will help.

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

@snoring_cat
I notice (in the snapshot of build commands in the previous posting) that 'Lint' is shown in light grey.
Your snapshot appears to be bold, not grey. I know nothing about Lint, except it is some sort of debugging tool (or something)

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: Learning C - I nobbled Geany

Post by snoring_cat »

Test 1
You could create the helloworld.c file in geany and save it to /root. Then remove the working directory path from the build command. If you can build helloworld and run it, maybe there was a path issue.

Test 2
Use your favorite diff tool on the following files, to see what is different

  • /root/.config/geany/geany.conf

  • /initrd/pup_ro2/root/.config/geany/geany.conf

Test 3
Backup your Geany configuration files, and have Geany recreate them. To do this, close down Geany and do the following:
mv /root/.config/geany /root/.config/geany_bak
After restarting Geany, you can see if you can get compiling to work. If things look better, then one of the files in your /root/.config/geany_bak was the culprit.

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

hello @snoring_cat
One advantage of a small problem: Tracking down the problem brings knowledge.
Addressing the point you made: Moved "hello" to /root (but not the root of the directory tree, /).
Opened, edited, compiled, built. No errors reported.
Below: you can see what happened in my terminal. Comments in blue.

# cd /root/; ls hell*
hello_world.c hello_world.o ...Here you see what is in the directory. I see the same in ROX.
# #My comment: there is no executable. ...This is the result of compiling, building, executing in Geany.
# gcc hello_world.c -o hi ...Now I compile, using the terminal. The executable will be "hi"
# ls hi* Is it there?
hi .... Yes! a small miracle. gcc loves me! ...
# #according to ROX 'hi' is executable. Let's see:
# hi
bash: hi: command not found ... Stuff up. I meant to type ./hi silly, silly, silly me ...
# ./hi
hello world the code, compiled by the gcc compiler runs, as expected.
# #I tried to run from a directory that was not in a declared path. Adding ./ fixed that. Yes, 4 lines above. My bad.
# #You understand what happened, I know.
# #Pasting from my terminal window onto the forum.

End of testing your point #1. It appears that there is no problem with path.
Moving to point #2 in your reply.

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

@snoring_cat

OK. This is what I did: Geany > tools > reload configuration; Then rebooted.
Now I'm back on the forum and loading hello_world from directory zzz/Computing/C/tut.

I can report: (1) Compile appears OK. After I click 'compile' I see a file hwllo_world.o This is the object code file
(2) Build appears to do nothing - hello_world.o already exists There is no executable code.

Looking in 'set build command' fr. Build menu I see this:

_4Cat--Set_Build_Command_#2.jpg
_4Cat--Set_Build_Command_#2.jpg (61.49 KiB) Viewed 877 times

I notice that the build box is empty.

Now to fiddle the system: in the terminal (the bash command line) I can compile hello_world.c : gcc hello_world.c works
I get an executable file called a.out. I can rename this executable to "hello_world" I can run "hello_world".
I have just demonstrated that the C compiler works from the terminal. OK. No big deal.
OK Trying this from a combination of Geany + ROX + Terminal

I compile the code using Geany -> hello_world.o (object code).
I change permission to executable (using Geany. I see x.)
In the terminal I type: ./hello_world.o an executable file. I get this error message
# ./hello_world.o
bash: ./hello_world.o: cannot execute binary file: Exec format error
#

And I don't understand the meaning of 'object code' in the context of linux. Previously I wrote a lot of code in assembly language.
Different processors. 8085, 68HC11, pic chips. Object code was an executable binary file; when loaded into memory and the program counter set to <some address> the object code ran. Maybe (here, in Linux) object code is similar, but without an executable permission.
Maybe. for the moment I will edit my source using Geany and compile and run using the terminal.
That's possible and for a few days easily done. Will return to this problem in a few days, when my mind is refreshed.
I think the source is compiling. I think the final step (object code to executable) isn't happening.
I think the parameters that control this change are missing (somewhere).

Cobaka.

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

I think I will read this: https://www.geany.org/manual/0.15/
I am somewhat further down the road than 0v15 but I think I may find an answer there.

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: Learning C - I nobbled Geany

Post by snoring_cat »

Hi cobaka,

Lint
I am not sure why your Lint line is greyed out. The Lint entry isn't necessary. It is used for program debugging. Lint is not being used...yet. Lint is a tool that used to be more popular. To translate Geany's Lint line -- we do not want to actually use Lint, but some tool to do "Code Checking". So the label should not be "Lint", but be "Code Check". In my case, the "Code Checking" command is the cppcheck command. I won't go into details of lint or cppcheck at the moment. Just know that gcc -Wall should be a sufficient alternative for common code checking. The -j option is for debugging, not code checking.

Making Progress
It is great that you were able to make your .o object file via Geany. We are making progress. The reason why you cannot build is because your "Build" entry doesn't have a command to run. So right now, clicking "Build" button does nothing. So just put in the following (as what was in my screenshot earlier):

Code: Select all

gcc -Wall -o "%e" "%f"

Afterwards, I think you should be fine making your executable from Geany.

Object Files
.o object files are like library files (e.g. .dll files in Windows and .so files in Linux). You can't directly run library files. But if you have an executable, it can link library files and use their functions, etc. For example:

Code: Select all

]ls -lh /usr/bin/viewnior
-rwxr-xr-x 1 root root 683K Aug 14 20:47 /usr/bin/viewnior


ldd /usr/bin/viewnior
	linux-vdso.so.1 (0x00007ffeca1d6000)
	/usr/lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007f1519083000)
	libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f1518c1f000)
	libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f1518b64000)
	libgdk_pixbuf-2.0.so.0 => /usr/lib/libgdk_pixbuf-2.0.so.0 (0x00007f1518b3c000)
	libgio-2.0.so.0 => /usr/lib/libgio-2.0.so.0 (0x00007f151895b000)
	libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f15188fb000)
	libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f15187d0000)
	libexiv2.so.14 => /usr/lib/libexiv2.so.14 (0x00007f1518328000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1518147000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1517ff8000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f1517fdd000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1517deb000)
	...

As can be seen, the "viewnior" is a small, 683kB application. It can display images in different formats. By using "ldd" we see that viewnior has many libraries linked to it. These libraries handle processing, JPG/GIF/BMP files, displaying user interfaces, etc. By linking in libraries a developer didn't have to write code for image handling, user interfaces, etc.

Viewnior uses .so library files, which stands for "shared object" files. When you compiled your program to a .o file, it is in a similar format that can be linkable to your real executable. As you learn C programming, a topic that you will be covering has to do with a linker to integrate your .o files.

Whew, that was a lot of typing. Hopefully this helps clear things up a little. Please note that the wording I used hopefully makes it less confusing then the actual textbook answer.

Meeeooow!

-- substance over noise, since 5 minutes in the future --

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: Learning C - I nobbled Geany

Post by williams2 »

I don't understand the meaning of 'object code' in the context of linux

You can write source code instructions for the computer.
The source is in a file named something.c

You can compile the source c file.
This converts the source instructions (that a humanc an understand, but a computer can not)
to a series of instructions that the cpu understands, and can execute.

The compiler can compile a standalone executable from the source.
Or the compiler can create an object file.
An object file is not intended to be executed directly.
An object file is intended to be linked to other object files, and maybe library shared object files.
to eventually create an executable or executables and maybe some .so shared object files.
Header files are important to the linking process.

You compile a single file of c source.

You build a complex project of multiple c source files, which creates object files which are linked together and with so files (which may be present as object files or as just header files).
Make is a tool commonly used for the build process.
You can build a project by hand, but it's easier to use make.

You compile a single c source file to produce an executable.
You do not build a single c source file to produce an executable.

From https://riptutorial.com/c/example/4360/the-linker

The job of the linker is to link together a bunch of object files (.o files) into a binary executable.

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

@snoring_cat

Again, thank you for your interest.
Progress appears close at hand.
From Geany - a few moments ago I compiled, built but could not run "hello.c".
I provide some detail so you can be certain I have no hidden no 'gotchas' in my directory.

I renamed file: hello_world.c -> hello.c ....There are no 'spooks' hanging around.
I confirm that there are only C source files in my directory called 'tut'. We, of course, are only interested in 'hello.c'
(I added a time stamp to 'hello' - the time will confirms that I am dealing with the source file I of interest.)
OK. That's all background. Back to Geany: I compiled (...tick I built ...tick
I clicking 'execute' -> nada, nothing ...
Using ROX, I see: hello.c and hello (executable). Switch to terminal window. You can see what happened.

# ./hello
hello world on 21-10.18 at 16:40
#

The important thing: The time is displayed correctly. This is the code I compiled and built a moment ago.
Now a strange thing: There is no object code (hello.o) in the directory.
I think building the file has converted the object file to an executable. (I would expect that).
So - my problem now seems to be: Geany made the executable, but can't find it to run it (or it doesn't open a terminal).
When I open the configuration box called "set build commands" I see three sections.
(1) for C commands. (2) for independent commands. (3) Execute commands.
In the last group the text is light grey. This is telling me something, but I don't know what ...

Thinking (now) about what happened below, when you told me, "Diff the files".

# diff /root/.config/geany/geany.conf /initrd/pup_ro2/root/.config/geany/geany.conf
[ cut many, many lines here ... ]

< run_in_vte=true ....<------------------- interesting
---
> run_in_vte=false ....<------------------- interesting diff. "vte" == ??something terminal emulator
238,240c230
< last_dir=/mnt/sda2/bThings/Computing/C/tut
< send_cmd_prefix=
< send_selection_unsafe=false
---
> last_dir=/root
250,255d239
< NF_01_LB=Make Custom _Target...
< NF_01_CM=\s
< NF_01_WD=
< NF_02_LB=Make _Object
< NF_02_CM=\s%e.o
< NF_02_WD=

Comment is welcome.
cobaka

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

I could re-install the Puppy OS. That can be done.
All I need to do is copy the OS files into a directory.

Maybe that's the solution.
Maybe that's not the solution bec. I learn nothing.
I already know how to install Puppy OS.

Cobaka

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: Learning C - I nobbled Geany

Post by snoring_cat »

Your settings look corrrect. In your config, the command that tells Geany to execute "hello" is

Code: Select all

NF_02_CM=\s%e.o

This is correct. This corresponds to the Execute line in Set Build Commands

set_build_commands-execute.jpg
set_build_commands-execute.jpg (16.16 KiB) Viewed 758 times

The good news is hello.c is compiling to hello. You do not need to create or use a hello.o.
You should be able to hit F5 or the run button. I'm not sure why your executable isn't running when you try either of those options. Odd. More thought will have to go into that.

The load_vte=true is not necessary. It just adds a terminal tab to the bottom message window, such as the following

vte.jpg
vte.jpg (50.9 KiB) Viewed 758 times

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: Learning C - I nobbled Geany

Post by snoring_cat »

Ahh, I think I found something. Please verify your Edit > Preferences

term.jpg
term.jpg (36.99 KiB) Viewed 756 times

Please make sure the line in blue is the same as what is on your computer.

Code: Select all

xterm -e bash -c -e "/bin/sh %c"

Hopefully you have xterm on your computer. If not, please replace xterm with rxvt

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - I nobbled Geany

Post by cobaka »

Hello @snoring_cat

I'm beginning to understand the "make" process.
At the same time I have a small understanding of how I created this confusion (for myself).
I have some chores today (before rain arrives) and I need an hour or so to completely understand the process of 'making' and executing. Now I have found the logic behind the process I think I can make Geany work.

In answer to your last posting, I supply a snapshot of my preferences.
In brief, the terminal is declared correctly. I note that my setup gives the full path.
When I type xterm in a terminal window, xterm opens/b] so ....
I have confirmed that the terminal is found in the directory seen in the path.
Slowly, slowly, I'm learning Puppy & Linux. This knowledge allows me to maintain my own PC (unlike Windows - the inscrutable).

_4Cat--term-prefs.jpg
_4Cat--term-prefs.jpg (53.96 KiB) Viewed 741 times

Thanks for your help.
Will post again when I understand more about 'making'.
I want to learn "C" well enough to compile & debug code written by others.
Becoming proficient with the Geany-compilation process is a small step to the final goal.

Cobaka

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: Learning C - I nobbled Geany

Post by williams2 »

You know that The C Programming Language First Edition by K&R
(somewhat out if date) is available here:
https://archive.org/download/TheCProgra ... rstEdition

By the way, qpdfview can display djvu files.

Also, you must know the Rosetta Code website, for example:
http://rosettacode.org/wiki/Sum_of_a_series

In case anyone reading this thread might find these 2 links useful.

Post Reply

Return to “Programming”