LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-29-2008, 07:11 AM   #1
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Rep: Reputation: 15
Unhappy GCC compilation returns a "cannot execute binary file" error


Hello, I'm using SUSE 10 on a 64-bit machine, and just recently started using Linux.I compiled a program successfully(no warnings or errors) in gcc using -o and -lm flags(it uses sqrt) and copied the resulting binary to the correct folder. But when I try to run the shell script relying on it, using bash, I get a "cannot execute binary file" error.The binary and script have full permissions to read&write, and are marked as executables.Can anyone explain what is the reason for this please?I'm a bit miffed-SUSE looks pretty nice overall, and now *this*.

PS. I cannot put the source code up here, as I'm not the developer and I don't have the developer's permission to do so.
 
Old 12-29-2008, 07:21 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Quote:
Originally Posted by Antongarou View Post
Hello, I'm using SUSE 10 on a 64-bit machine, and just recently started using Linux.I compiled a program successfully(no warnings or errors) in gcc using -o and -lm flags(it uses sqrt) and copied the resulting binary to the correct folder. But when I try to run the shell script relying on it, using bash, I get a "cannot execute binary file" error.The binary and script have full permissions to read&write, and are marked as executables.Can anyone explain what is the reason for this please?I'm a bit miffed-SUSE looks pretty nice overall, and now *this*.

PS. I cannot put the source code up here, as I'm not the developer and I don't have the developer's permission to do so.
Is it a C or a C++ program? And what command exactly did you use to compile the source? (don't need to post the source, just tell which commands used to compile and whether it is a C or a C++ program)
 
Old 12-29-2008, 07:22 AM   #3
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Can you execute the binary directly off the commandline?
Can you show us the bash script?

Note: if there is a problem with the code, we will not be able to help. You should consider asking the developer to release the code using a free software or open source license.
 
Old 12-29-2008, 07:32 AM   #4
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Mega Man X View Post
Is it a C or a C++ program? And what command exactly did you use to compile the source? (don't need to post the source, just tell which commands used to compile and whether it is a C or a C++ program)
I'm pretty sure it's a C++ program(it uses "struct") and I compiled it with the command gcc -o onefile2nii -lm onefile2nii.c
 
Old 12-29-2008, 07:39 AM   #5
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Quote:
Originally Posted by Antongarou View Post
I'm pretty sure it's a C++ program(it uses "struct") and I compiled it with the command gcc -o onefile2nii -lm onefile2nii.c
Ah, that is strange, because if it is a c++ program, it should have an extension like "cc" or "cpp", instead of "c". If that affects the compiler, I don't really know

Also, if it is a C++ program, it should be compile with "g++" command, not "gcc". Ex:

g++ -o onefile2nii -lm onefile2nii.cpp

Ask the developers to give it a shot and use the extension "c/cpp" properly as well.
 
Old 12-29-2008, 07:41 AM   #6
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Simon Bridge View Post
Can you execute the binary directly off the commandline?
Can you show us the bash script?

Note: if there is a problem with the code, we will not be able to help. You should consider asking the developer to release the code using a free software or open source license.
No, when I try the terminal can't seem to even find it.
As to the script, I'd be happy to, but it's pretty long.The relevant lines are
Code:
command="bash onefile2nii -I $outfile $1 $outfilename"
echo "executing: $command"
$command
If you need a more complete look the file called makenifti in http://rsl.stanford.edu/glover/fmriutil/linux/ contains the whole scripts.

PS>I'm pretty sure the code is OK- people have been using this tools for more then a year in Stanford and didn't have any problem.
 
Old 12-29-2008, 07:47 AM   #7
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Mega Man X View Post
g++ -o onefile2nii -lm onefile2nii.cpp
My computer doesn't know the command- which packages do I need installed?I have gcc41-c++ and gcc42-c++ installed.

ETA:Nevermind.found out

Last edited by Antongarou; 12-29-2008 at 08:07 AM.
 
Old 12-29-2008, 02:50 PM   #8
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Quote:
Originally Posted by Antongarou View Post
My computer doesn't know the command- which packages do I need installed?I have gcc41-c++ and gcc42-c++ installed.

ETA:Nevermind.found out
Cool so, did it you install the package? Which package was it? Did it work to compile the code? Did you rename it to cpp? Answering those questions could help somebody facing the same issue
 
Old 12-29-2008, 11:50 PM   #9
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Sorry.It's the gcc-c++ basic package, which apparently isn't necessarily installed even if you have other gcc*-c++ packages installed.It recognizes the code but won't compile it over some apparent coding problems, which I'm currently working through.
 
Old 12-30-2008, 12:14 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
C programs use struct as well. You have a c program.

Where did you copy the file to. Compile the program in your home directory where you have full permissions. Don't compile programs in /tmp. It may be mounted with the "noexec" and "nolib" options.

Make sure you have the "binutils" package installed. It is needed to produce libraries and supplies the loader. You probably have it installed.

Since you use SuSE, run the yast package manager: "kdesu yast2 sw_single"

Search for 'c++' and 'gcc'. The g++ frontend is supplied by the gcc-c++ package. Also look at other packages that show up, such as 'libstdc++'.

Also, if a program is in the same directory, precede the file name with `./' to run it. The current path isn't normally in PATH for security reasons.

Last edited by jschiwal; 12-30-2008 at 12:16 AM.
 
Old 12-31-2008, 04:51 AM   #11
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
If it is a c program then I still have the same problem.It won't work, even when compiled and run under a root session.I also made sure that I had full permissions for the folders I compile and run it on, and both of them are subdirectories of /home/


PS. "binutils" is indeed installed.What kind of c/c++ packages am I looking for?There is quite a number, some of them rather big, and I don't see a reason to clutter my HD with, 100s of MBs of stuff I won't use.
 
Old 01-01-2009, 08:06 AM   #12
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
The command you are trying to run:

bash onefile2nii -I $outfile $1 $outfilename

assumes that onefile2nii is in the same directory as the script, or in your PATH. Is this the case?
(though if it were otherwise, I'd expect a "file not found" error but it won't hurt.)

thing is, I'd have expected the command to run as:

bash -c onefile2nii -I $outfile $1 $outfilename

or just

./onefile2nii -I $outfile $1 $outfilename

note: if the program must have all three inputs, then it will fail if any are missing. Make sure they are all supplied.

The variable names look a bit odd... check them - what is the difference between outfile and outfilename?

from the program name, it looks like a utility to convert a onefile to nii (whatever those are), so I would have expected the first to be called onefile rather than outfile, making the command:

./onefile2nii -I $onefile $1 $outfilename

Last edited by Simon Bridge; 01-01-2009 at 08:10 AM.
 
Old 01-02-2009, 06:29 AM   #13
Antongarou
Member
 
Registered: Dec 2008
Posts: 31

Original Poster
Rep: Reputation: 15
An Update:I found out that the program compiles and works fine when used on an Ubuntu machine(we have some at work), so it's probably a matter of OS defaults.I'll be converting my machine to Ubuntu as a result.
 
Old 01-03-2009, 07:28 PM   #14
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
On my Ubuntu system - I can try executing a binary file with a bash cammand like your script tries to do... here's what happens:

simon@indigo-prime:~$ bash ls
/bin/ls: /bin/ls: cannot execute binary file

but if I use

bash -c ls

it works -

i.e. If you use the same script, changing to Ubuntu won't help.

So you need to change the script you use to execute the program

You seem highly reluctant to follow advise.
 
  


Reply



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
None of the compliers working, a "can not execute binary file" problem jason_zhang Linux - Newbie 3 10-26-2008 12:29 PM
Assembly, "bash: ./exit: cannot execute binary file" User Name. Programming 4 08-07-2007 09:09 AM
[SOLVED] Installind Slamd64-current. "cannot execute binary file" message about installpkg BrutalMusic Slackware - Installation 1 05-11-2006 09:35 AM
"cannot execute binary file" when install j2sdk jin007 Linux - Software 3 06-27-2005 02:05 PM
SIN linux native - "cannot execute binary file" darkranger Linux - Games 1 06-07-2005 08:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:01 AM.

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