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. |
Quote:
|
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. |
Quote:
|
Quote:
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. |
Quote:
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" 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. |
Quote:
ETA:Nevermind.found out |
Quote:
|
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.
|
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. |
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. |
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 |
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.
|
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. |