LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 02-12-2007, 05:28 AM   #1
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Rep: Reputation: 15
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
 
Old 02-12-2007, 06:17 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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 .
 
Old 02-12-2007, 06:19 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
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.
 
Old 02-12-2007, 06:28 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.
  1. 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.
  2. 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:
    Code:
    make
    make install
    Then, each time the system comes up, do this:

    Code:
    modprobe mbdialer
  3. 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.
 
Old 02-12-2007, 07:08 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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).
 
Old 02-12-2007, 07:43 AM   #6
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
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
 
Old 02-12-2007, 08:09 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-12-2007, 08:51 AM   #8
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
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
 
Old 02-12-2007, 08:59 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-12-2007, 10:00 AM   #10
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
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'
 
Old 02-12-2007, 11:24 AM   #11
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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
Code:
CC=gcc
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:

Code:
make
make install
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.
 
Old 02-12-2007, 11:18 PM   #12
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
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.
 
Old 02-13-2007, 01:56 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-13-2007, 04:51 AM   #14
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
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
 
Old 02-19-2007, 02:07 AM   #15
SunitaChandrasekaran
LQ Newbie
 
Registered: Feb 2007
Posts: 3

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot execute binary file sonia gulrajani Programming 3 11-05-2006 01:30 AM
Cannot Execute Binary File meshcurrent Linux - Software 3 07-09-2005 03:39 PM
cannot execute binary file babaliciouse Linux - Software 2 10-21-2004 11:50 AM
Cannot execute binary file pbagda Linux - General 4 01-19-2004 01:13 AM
cannot execute binary file azpeitia Red Hat 2 12-17-2003 12:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration