Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
02-12-2007, 05:28 AM
|
#1
|
Member
Registered: Jul 2006
Posts: 100
Rep:
|
Cannot execute binary file
Hiii,
I have the libmodbus driver downloaded from the sourceforge.net, and i compile that driver from the Makefile in the driver, and it creates the mbdialer.o, but when i tried to run it, it didnt run and shows that cannot execute the binary file
the gcc command to create the mbdialer.o is
CC=gcc
$(FLAGS) $(CC) -c mbdialer.c -l
------------------------------------------
can anybody please help me to understand why the bianry file is not running? should i do the -o to create the executable binary file? if yes what about the -l option where no library file has been linked?
Hope for the prompt and positive reply.
Thanks,
Nishant
|
|
|
02-12-2007, 06:17 AM
|
#2
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
How are u trying to run it ?
If its a driver file you dont execute it .
But you load it as kernel module.
Read the Readme.txt that comes with the driver .
|
|
|
02-12-2007, 06:19 AM
|
#3
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
Sounds like it isn't supposed to be an executable binary, but a module instead. If it's a kernel module you'll have to use insmod or modprobe to load the module before you can use it.
|
|
|
02-12-2007, 06:28 AM
|
#4
|
Member
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Rep:
|
First, a suggestion.
When you bring a situation like this to linuxquestions or any other online forum, it is usually wise, rather than saying "this didn't work", to show the exact error message that occurred when you tried it. It is also wise to be more specific about how you ran it. Did you run it by typing something at the command line? If so, what was the exact command?
Since you didn't give any of that, I went and downloaded the package myself. (You did well when you said where you got it! (grin))
I found several things that may be of interest. - As you probably know, the best way to generate all this stuff is with the make command. In Makefile, the command to compile mbdialer.o is not
Code:
$(FLAGS) $(CC) -c mbdialer.c -l
(that's an ell at the end), but rather (as seen in Makefile)
Code:
$(CC) $(CFLAGS) -c mbdialer.c -I.
(that's an eye period at the end).
My guess is that you typed that command by hand when you wrote your linuxquestions post. It's always better to cut and paste, so as to make an accurate copy.
There's nothing wrong with the command as it actually is. It produces mbdialer.o properly.
- mbdialer.o is not an executable program; it's a module, meant to be linked with something else. As a rule, you should not expect to be able to run .o files at the command line.
You'd expect it to be the .o file that it is, because it's a driver. The way to use drivers is not to run them at the command line, but to load them into the operating system.
To build the module, do this as root:
Then, each time the system comes up, do this:
- Once that module is installed, you get to write your own program to use it. You get some help with that, because this package also comes with a library called libmodbus. The make install not only puts the driver module where it belongs, but also puts libmodbus.so where it belongs. (I'm assuming this; I built it, but did not install it.)
The author of the package provided some documentation in the form of file libmodbus.html. Read that file.
He also provided sample programs. He compiled them ahead of time, which is not normally done; normally the make command should do this.
You can learn a lot by looking at the example source code files. But you can also compile them yourself and run them. Instructions for doing that are in the source files themselves.
Hope this helps.
|
|
|
02-12-2007, 07:08 AM
|
#5
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
$(CC) $(CFLAGS) -c mbdialer.c -I.
|
We can notice another clue, here: it is the -c option which tells to compiler to not create an executable, but simply an object file which will be linked to an executable later (usually together with other object files).
|
|
|
02-12-2007, 07:43 AM
|
#6
|
Member
Registered: Jul 2006
Posts: 100
Original Poster
Rep:
|
Quote:
Originally Posted by colucix
We can notice another clue, here: it is the -c option which tells to compiler to not create an executable, but simply an object file which will be linked to an executable later (usually together with other object files).
|
Thanks to everybody,
Hii all thanks to all of you for your help, now from this i got the exact problem and i also ran the example given inside and it also runs successfully, and i also foound how to compile those programs.
Now my concern is to cross-compile for this program to run it on the ARM board and for that i want to change the gcc path, can anybody tell me the exact command to change the path? i tried with
set PATH = /usr/local/arm/2.95.3/bin:$PATH
set PATH = "/usr/local/arm/2.95.3/bin:$PATH" and the directory "/usr/local/arm/2.95.3/bin" is my path where my gcc is lied in, what is the mistake i am doing? I am standing in the bash shell.
Another concern is my gcc has the name arm-linux-gcc, should i join arm-linux string after my path like i have shown here, (/usr/local/arm/2.95.3/bin/arm-linux-)? by doing this things i am not able to set the exact PATH, can anybody tell me exact way to set the PATH for my gcc?
Thanks,
Nishant
|
|
|
02-12-2007, 08:09 AM
|
#7
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by Nishant Desai
set PATH = /usr/local/arm/2.95.3/bin:$PATH
|
The correct syntax for adding a directory to your own PATH is
Code:
export PATH=/usr/local/arm/2.95.3/bin:$PATH
You can notice:
1) the export command used instead of set: this tells to make the PATH environment variable as global, that is: all the subsequent commands know about the modification of your PATH.
2) no blank space left around the "=" sign, otherwise you don't get the expected result.
3) The modification to your PATH is active in the current bash session only. To make it available to all the bash sessions, that is each time you open a terminal, you can put the above command in the $HOME/.bashrc file.
Regarding the name of the executable, I suggest to leave it as is, e.g. you can launch it as in
Code:
arm-linux-gcc somefile.c
this will remember to you what you are doing (cross-compiling in this case) and avoids to change the PATH every time you need to use the GNU gcc compiler. Indeed you don't really need to change the PATH if you launch the command with its full path, as in
Code:
/usr/local/arm/2.95.3/bin/arm-linux-gcc somefile.c
Last edited by colucix; 02-12-2007 at 08:11 AM.
|
|
|
02-12-2007, 08:51 AM
|
#8
|
Member
Registered: Jul 2006
Posts: 100
Original Poster
Rep:
|
Quote:
Originally Posted by colucix
The correct syntax for adding a directory to your own PATH is
Code:
export PATH=/usr/local/arm/2.95.3/bin:$PATH
You can notice:
1) the export command used instead of set: this tells to make the PATH environment variable as global, that is: all the subsequent commands know about the modification of your PATH.
2) no blank space left around the "=" sign, otherwise you don't get the expected result.
3) The modification to your PATH is active in the current bash session only. To make it available to all the bash sessions, that is each time you open a terminal, you can put the above command in the $HOME/.bashrc file.
Regarding the name of the executable, I suggest to leave it as is, e.g. you can launch it as in
Code:
arm-linux-gcc somefile.c
this will remember to you what you are doing (cross-compiling in this case) and avoids to change the PATH every time you need to use the GNU gcc compiler. Indeed you don't really need to change the PATH if you launch the command with its full path, as in
Code:
/usr/local/arm/2.95.3/bin/arm-linux-gcc somefile.c
|
Hiii,
The PATH has been set successfully by the command you have given, but then it gave me the error that the /usr/local/arm/2.95.3/arm-linux/bin/ld: cannot find the "-lmodbus", the lmodbus file is the one which i am including to compile my program and its a driver for the file to run.
Now when my path was normal, that is GNU gcc's path at the time this file was in /usr/include, and it was running, but now when i did this path, it shows me this error, can you please tell me in which directory i should put my -lmodbus? from which it can use this file to compile the code and make the executable file.
Hope for the quick reply.
Thanks,
Nishant
|
|
|
02-12-2007, 08:59 AM
|
#9
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Please, post your complete command line (the one you use to compile). If the file you mentioned is still in /usr/include you can add the -I/usr/include option at the end of the compiling command (even if this is a default location for includes file and should always be found from the ld linker). If it is a file specific for the arm-linux-gcc cross compiler, look for its location and append the -I option accordingly.
|
|
|
02-12-2007, 10:00 AM
|
#10
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
After exporting the path do
LD_LIBRARY_PATH=/path/where/libmodbus is installed.
For my cross-compilers or alterante compilers, I write a small wrapper which sets all this up easily:
#!/bin/sh
export PATH=/opt/gcc-2.95/bin:$PATH
export LD_LIBRARY_PATH=/opt/gcc-2.95/lib
exec "$@"
Adjust for your needs, then name it GCC295 and place in your path (usr/local/bin). Ther when you want to compile something with it just type:
'GCC295 make'
|
|
|
02-12-2007, 11:24 AM
|
#11
|
Member
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Rep:
|
You need the cross compiler for both the driver itself and your user program?
For the driver itself, since you're using a non-normal compiler while doing make, don't use PATH to get that compiler. Instead, edit the Makefile. Your particular Makefile has a line near the beginning of it that says
Change it to read:
Code:
CC=/usr/local/arm/2.95.3/bin/arm-linux-gcc
One purpose of make is to insure that you don't have to repeat parts of the build process you have already accomplished. But if you've already run make on this program and you change the CC= line, you're going to have to "fool" make into thinking that you need to do it all again. So this time, instead of saying:
you need to say:
Code:
make clean
make
make install
For your user program, simply modify the directions given at the beginning of the sample programs in this package:
Code:
/usr/local/arm/2.95.3/bin/arm-linux-gcc master-example.c -o master-example -lmodbus
/usr/local/arm/2.95.3/bin/arm-linux-gcc slave-example.c -o slave-example -lmodbus
Last edited by wjevans_7d1@yahoo.co; 02-12-2007 at 11:42 AM.
|
|
|
02-12-2007, 11:18 PM
|
#12
|
Member
Registered: Jul 2006
Posts: 100
Original Poster
Rep:
|
Hiii,
Now i got what you guys are saying, and the file should be in the /arm-linux/lib and my code is also working and i have successfully cross-compile my code for the ARM board.
Now in the Ramdisk given with the board contains the /dev folder, but it does not contain the /ttyS) from which i can access the serial port as we are generally using in the desktop to access the serial port.
can anybody please tell me what should i do to access the serial port? should i have to create the node in the /dev folder with the serial port driver?
What is the exact method to create the node which can access the serial port?
Thanks,
Nishant
Last edited by Nishant Desai; 02-12-2007 at 11:20 PM.
|
|
|
02-13-2007, 01:56 AM
|
#13
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
It would be better to open another thread, since the topic is quite different from the original. Anyway, the nodes should be created automatically upon hardware detection. On which linux/unix distribution are you running? For now, I can suggest to read the good Serial HOWTO from the Linux Documentation Project.
|
|
|
02-13-2007, 04:51 AM
|
#14
|
Member
Registered: Jul 2006
Posts: 100
Original Poster
Rep:
|
Hiii All,
As per the Colucix's request i start the new thread for the further discussion, so please refer to the below thread:
http://www.linuxquestions.org/questi...67#post2628567
I am getting the error in loading the library file libmodbus.so that R_ARM_PC24 relocation is out of range. I have explain the condition there.
Hope for the prompt reply.
Thanks,
Nishant
|
|
|
02-19-2007, 02:07 AM
|
#15
|
LQ Newbie
Registered: Feb 2007
Posts: 3
Rep:
|
open64 compiler
Hi
I am trying to install open64 compiler and its associated tool Dragon on to AMD opteron machine
My OS is opensuse 10.2 with kernel version of 2.6.18
To generate call graph, I am supposed to go where Dragon has got installed and give
code: opencc -dragon -ipa -O2 test.c
i get the [B]error message : bash: /usr/bin/opencc: cannot execute binary file [B]
May I know why is it getting stuck there?
Thanks
Sunita
|
|
|
All times are GMT -5. The time now is 11:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|