LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 11-03-2006, 04:01 AM   #1
sonia gulrajani
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Rep: Reputation: 0
Unhappy Cannot execute binary file


Hi,

I am a beginner with programming on linux.

I need to write a program using Libpcap
I downloaded and installed the package from tcpdump.org and can see the library libpcap.a at the location /usr/lib.

I have the following sample program named as test.c:

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];

dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(1);
}
printf("Device: %s\n", dev);
return(0);
}



Following are the steps using which i compile it

gcc -c test.c
gcc test.o -lpcap
./test.o
-bash: ./test1.o: cannot execute binary file

I don't know why i am getting the above error . I changed the permission of the object file to 777, it still does not work. Any other c program runs perfectly fine.

Any help in this will be appreciated.

Regards,
Sonia
 
Old 11-03-2006, 07:29 AM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
The problem is that test.o es an object file, not an ELF. So you should look for the a.out file generated after the second gcc line. If you want to name it something else you could add -o myProgram when you do your second gcc line (the linking).


Cheers!
 
Old 11-04-2006, 06:38 PM   #3
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
You should also be able to do the compile and link as one step, e.g.:
Code:
gcc -s test.c -lpcap -o test
which would generate an executable binary named 'test'
 
Old 11-05-2006, 01:30 AM   #4
sonia gulrajani
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Original Poster
Rep: Reputation: 0
thanks!

thanks! it worked
 
  


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
Cannot execute binary file Sigh Linux - Server 4 09-22-2006 07:43 AM
cannot execute binary file Quest101 Linux From Scratch 8 11-19-2004 01:16 PM
Cannot execute binary file Nooodle007 Linux - Software 2 06-25-2003 01:25 PM
Cannot execute binary file Bigun Linux - Software 17 11-03-2002 06:12 PM
cannot execute binary file.... ttaylor Linux - General 4 10-02-2001 01:37 AM

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

All times are GMT -5. The time now is 04:13 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