GCC compilation returns a "cannot execute binary file" error
Linux - NewbieThis 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
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.
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.
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.
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)
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.
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
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.
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
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.