LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   GCC compilation returns a "cannot execute binary file" error (https://www.linuxquestions.org/questions/linux-newbie-8/gcc-compilation-returns-a-cannot-execute-binary-file-error-693627/)

Antongarou 12-29-2008 07:11 AM

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.

Mega Man X 12-29-2008 07:21 AM

Quote:

Originally Posted by Antongarou (Post 3390269)
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)

Simon Bridge 12-29-2008 07:22 AM

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.

Antongarou 12-29-2008 07:32 AM

Quote:

Originally Posted by Mega Man X (Post 3390280)
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

Mega Man X 12-29-2008 07:39 AM

Quote:

Originally Posted by Antongarou (Post 3390291)
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.

Antongarou 12-29-2008 07:41 AM

Quote:

Originally Posted by Simon Bridge (Post 3390282)
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.

Antongarou 12-29-2008 07:47 AM

Quote:

Originally Posted by Mega Man X (Post 3390297)
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

Mega Man X 12-29-2008 02:50 PM

Quote:

Originally Posted by Antongarou (Post 3390307)
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 :)

Antongarou 12-29-2008 11:50 PM

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.

jschiwal 12-30-2008 12:14 AM

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.

Antongarou 12-31-2008 04:51 AM

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.

Simon Bridge 01-01-2009 08:06 AM

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

Antongarou 01-02-2009 06:29 AM

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.

Simon Bridge 01-03-2009 07:28 PM

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.


All times are GMT -5. The time now is 08:55 PM.