Page 1 of 1
Geany generates wrong format executables
Posted: Sat Oct 07, 2017 1:06 am
by VALERYRAMIREZ
Hello everyone, I have some problems with the example of the ir receiver on a Nanopi M1, I decided to modify the original demo program to match de embedded ir receiver but when I try to ececute the program, the information that I have until now is:
The version of geany is: 1.24.1
The response of the console when I try to run the program is:
Code: Select all
./geany_run_script.sh: 5: ./geany_run_script.sh: ./Matrix-ir_receiver: Permission denied
------------------
(Program exited with code: 126)
Press return to continue
after that I press Enter and the terminal closes.
As you can see, I couldn't run the executable as root user, after that I saw properties of the program and noted that the permissions was set to "fa" on group "fa", changed all to root on group root it says:
Code: Select all
root@friendlyELEC:/matrix/demo/matrix-ir_receiver# ./Matrix-ir_receiver
bash: ./Matrix-ir_receiver: cannot execute binary file: Exec format error
when I see the properties of the executable, it doesn't say "executable" in the file type but "object code" file type.
My commands are:
Compile:
Build:
before that the command Build isn't had the -c option, it was added because the build command was giving me a lot of errors of the type "don't recognize several functions related to the I/O ports"
Re: Geany generates wrong format executables
Posted: Sat Oct 07, 2017 2:59 am
by davef
Last things first ... have you more than one .c file that you are trying to cross-compile?
./geany_run_script.sh: . . .
Did you try running like this:
sudo ./geany_run_script.sh
Geany is an editor, it has nothing to do with the cross-compile process.
Do you get anything when you drop
(Program exited with code: 126)
into Google.
You can always check your executable with:
readelf -A <the_file_name> to make sure your toolchain is set up correctly.
Re: Geany generates wrong format executables
Posted: Sat Oct 07, 2017 10:56 am
by VALERYRAMIREZ
davef wrote:Last things first ... have you more than one .c file that you are trying to cross-compile?
./geany_run_script.sh: . . .
Did you try running like this:
sudo ./geany_run_script.sh
Geany is an editor, it has nothing to do with the cross-compile process.
Do you get anything when you drop
(Program exited with code: 126)
into Google.
You can always check your executable with:
readelf -A <the_file_name> to make sure your toolchain is set up correctly.
Hi Davef, Thank you for your answer.
The response for code 126 was because by the time I didn't have permission to execute the file, after that I've changed the permissions (included the owner to root) of the file through chmod. After change permissions is when it shows the message "Bad exec file format"
The readelf gave this answer:
Code: Select all
Attribute Section aeabi
File Attributes
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Tag_CPU__arch_profile: Application
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv3-D16
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_presserved: 8-byte, except leaf SP
Tag_ABI__enum_size: int
Tag_ABI_Hard_use: SP and DP
Tag_ABI_VFP_args: VFP registers
Tag_ABI_optimization_goals: aggressive Debug
Tag_CPU_unaligned_access: v6
At this time I don't know what this means but I will search.
Uppsss!! I forgot to tell that I'm using the debian jessie 3.4... that provides friendlyarm.
Re: Geany generates wrong format executables
Posted: Sat Oct 07, 2017 6:18 pm
by davef
Tag_CPU_arch: v7
Is the line you are after. I don't know which arm version your board uses, so you will need to search around for that.
Have you been able to cross-compile any programs for your target?
Looking back at your original post I would have not expect you to call "gcc" but something more like 'arm-linux guneabihf-gcc". However, it does appear to be cross-compiled for ARM. Have you got a HowTo cross-compile tutorial for your target? Point me to it.
Which toolchain have you got in your EXPORT path in .bashrc
Re: Geany generates wrong format executables
Posted: Sat Oct 07, 2017 8:41 pm
by VALERYRAMIREZ
quote="davef"]
Tag_CPU_arch: v7
Is the line you are after. I don't know which arm version your board uses, so you will need to search around for that.
Have you been able to cross-compile any programs for your target?
Looking back at your original post I would have not expect you to call "gcc" but something more like 'arm-linux guneabihf-gcc". However, it does appear to be cross-compiled for ARM. Have you got a HowTo cross-compile tutorial for your target? Point me to it.
Which toolchain have you got in your EXPORT path in .bashrc[/quote]
Look, untill now and reading in stackoverflow I'm thinking that I've made a big mistake by adding the -c option in the build command, I did that becuase it was giving me a lot of errors with undefined references, like this one if I let the Build command like it commes with the preinstalled Geany:
Code: Select all
/tmp/ccwWOISx.o in function 'IRintHandler':
prueba.c (text + 0x26): undefined reference to closeHW
In the function main it says:
Code: Select all
/tmp/ccwWOISx.o in function 'main'
...... undefined reference to 'boardinit'
...... undefined reference to 'pintoGPIO'
...... undefined reference to 'openHW'
...... undefined reference to 'selectHW'
...... undefined reference to 'readHW'
...... undefined reference to 'closeHW'
......
......
and about two or tree more errors of the same type "undefined reference" all related a functions of the hardware
so I think (if I've understood what I readed) that is a linking error but don't know how to solve it.
I didn't cross-compile any of the programs, they came cross-compiled from friendlyarm.
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 1:44 am
by davef
davef wrote:
Last things first ... have you more than one .c file that you are trying to cross-compile?
If you are trying to cross-compile more than one .c file on the command line you need to
something like:
Code: Select all
arm-linux-gnueabihf-gcc -Wall PB.c 1wire.c gpio.c adc.c -o PB
... unless you want to learn about makefiles.
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 2:02 am
by VALERYRAMIREZ
davef wrote:davef wrote:
Last things first ... have you more than one .c file that you are trying to cross-compile?
If you are trying to cross-compile more than one .c file on the command line you need to
something like:
Code: Select all
arm-linux-gnueabihf-gcc -Wall PB.c 1wire.c gpio.c adc.c -o PB
... unless you want to learn about makefiles.
Thank you for the help, I'm cross-compile only ine file, I want to learn about makefiles but I need to learn the basics first, I've almost sure that I'm missing the file where are the definitions of the hardware functions, is only that I can't find it to includ it in the file that I'm trying to execute
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 5:02 am
by davef
Yes, at the top of the .c file you should see #includes all you need to do if find out where those files are and make sure they are in the location pointed to.
If the .h file is enclosed in " " then they should be in a local folder with your .c file. If you are compiling from the command line then all #includes need to be in the local folder.
If they are enclosed in <> they would be in a location specified in the makefile. If you are not using a makefile then things will get complicated. I could make some suggestions.
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 7:48 pm
by VALERYRAMIREZ
davef wrote:
Yes, at the top of the .c file you should see #includes all you need to do if find out where those files are and make sure they are in the location pointed to.
If the .h file is enclosed in " " then they should be in a local folder with your .c file. If you are compiling from the command line then all #includes need to be in the local folder.
If they are enclosed in <> they would be in a location specified in the makefile. If you are not using a makefile then things will get complicated. I could make some suggestions.
Thanks again Davef, I've found that some if not all the functions what are giving errors of reference in the files are made in the file gpio.c but I couldn't find the gpio.h where the definitions should be. I'm open to any suggestions that you can give
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 10:00 pm
by davef
Show me the contents of:
geany_run_script.sh
Where did you get the script from? How did you find gpio.c ? Looks like it is part of a package that you don't have all of the files. WiringPI or the FriendlyArm version?
Re: Geany generates wrong format executables
Posted: Sun Oct 08, 2017 11:43 pm
by VALERYRAMIREZ
davef wrote:
Show me the contents of:
geany_run_script.sh
Where did you get the script from? How did you find gpio.c ? Looks like it is part of a package that you don't have all of the files. WiringPI or the FriendlyArm version?
Well, right now geany_run_script.sh must show that file doesn't exist because of the error building the executable, gpio.c is in /matrix/lib and in /matrix/lib/includes is a file called libfahw-gpio.h where are defined this functions:
Code: Select all
initPinGPIO
pintoGPIO
exportGPIOPin
unexportGPIOPin
and others set directions and values of the pins but I can't find those related to openHW, closeHW, etc, etc which seems to be related with kernel (if I'm correct)
The libraries where cloned and installed from friendlyarm matrix github, I'll look again the github but they don't seems to be in that github.
Re: Geany generates wrong format executables
Posted: Mon Oct 09, 2017 12:55 am
by VALERYRAMIREZ
Re: Geany generates wrong format executables
Posted: Mon Oct 09, 2017 1:14 am
by VALERYRAMIREZ
davef wrote:
Yes, at the top of the .c file you should see #includes all you need to do if find out where those files are and make sure they are in the location pointed to.
If the .h file is enclosed in " " then they should be in a local folder with your .c file. If you are compiling from the command line then all #includes need to be in the local folder.
If they are enclosed in <> they would be in a location specified in the makefile. If you are not using a makefile then things will get complicated. I could make some suggestions.
Well davef, reading again this comment, I decided to look into the makefile of the folder and I saw this:
Code: Select all
CC = gcc
TARGET = $(patsubst Matrix-%.c,matrix-%, $(wildcard *.c))
SRC = $(wildcard *.c)
SRC += $(wildcard *.h)
$(TARGET):$(SRC)
$(CC) -o $0 -L ../../lib/ -I ../../lib/includes/ $^ -lfahw -lm -Wall
.PHONY: clean
clean:
rm -f $(TARGET)
I don't understand almost any of what it says but when I saw the following build options:
I've remembered a recent forum readed in stackoverflow about reference erros with math functions and after that I've decided to include those options in the Build command and voila, the code worked...Yeaaaaah!!!!!
I'm still having several big doubts, why if the makefile is in the same folder, geany doesn't read the makefile?, and I now that the compiler is cross-compiled (forgive de redundancy) to make it work in an ARM device but, where looks the compiler to find and use the options -lfahw (I think specifically for this device...kernel, I don't know) and the -lm option?.
Re: Geany generates wrong format executables
Posted: Mon Oct 09, 2017 2:24 am
by davef
Ah, you do have a makefile but you are not using it? Also, it looks like you are working with the Matrix or BitBake tools.
I am confused by your reference to Geany. I am sure it is just an editor not an IDE, correct me if I am wrong as I actually use it as an editor only.
I have done some matrix stuff and yes it appears when you place a specific cross-compile request on the command line something knows to go looking for the makefile, maybe if there is one.
Have you tried just doing one of FriendlyArms simple examples first?
Re: Geany generates wrong format executables
Posted: Mon Oct 09, 2017 3:52 pm
by VALERYRAMIREZ
davef wrote:
Ah, you do have a makefile but you are not using it? Also, it looks like you are working with the Matrix or BitBake tools.
I am confused by your reference to Geany. I am sure it is just an editor not an IDE, correct me if I am wrong as I actually use it as an editor only.
I have done some matrix stuff and yes it appears when you place a specific cross-compile request on the command line something knows to go looking for the makefile, maybe if there is one.
Have you tried just doing one of FriendlyArms simple examples first?
Well, this program is an example of the matrix, specifically the matrix-ir_receiver, all examples come with the makefile, the executable, the .o and the .c file but I don't konw how to use the makefile in geany.
Your right, Geany is an editor with some configurable buttons, those buttons can run compile options, build, etc. depending on what you configured.By that time I used the default configuration of the buttons but last nigth, after see the makefile I've added the options -lfahw (friendlyarm hardware?) and -lm (math) -if one is left outside, it gives errors- but I don't know how to use the makefile from Geany; in fact, I could run the modified example from Geany after add the options in the build command (button of geany)
Re: Geany generates wrong format executables
Posted: Mon Oct 09, 2017 7:07 pm
by davef
"Live and learn". Geany became my default "editor" after my last Xubuntu upgrade instead of gedit. Now I know it is more capable than I first thought.
Seeing as your issue is totally related to Geany use I would suggest looking around for a Geany forum or a Geany Wiki where they should have good tutorials.
Good luck
Re: Geany generates wrong format executables
Posted: Tue Oct 10, 2017 2:48 pm
by VALERYRAMIREZ