In ubuntu, when eclipse is used to call the libpcap library to write a small program, the following error occurs: pcap. H is not involved in compilation.

Source: Internet
Author: User

This is what Winpcap or libpcap programmers are trying for the first time. It seems that it is just C after helloworld, but it still leaves me scratching my head for a day.

# Include "pcap. H "int main () {pcap_if_t * alldevs; pcap_if_t * D; int I = 0; char errbuf [pcap_errbuf_size]; /* get the list of local devices */If (pcap_findalldevs (& alldevs, errbuf) =-1) {fprintf (stderr, "error in pcap_findalldevs_ex: % s \ n ", errbuf); return 1;}/* print list */For (D = alldevs; D! = NULL; D = D-> next) {printf ("% d. % s ", ++ I, d-> name); If (D-> description) printf (" (% s) \ n ", D-> description ); else printf ("(no description available) \ n");} if (I = 0) {printf ("\ Nno interfaces found! Make sure Winpcap is installed. \ n "); return 1;}/* no longer requires a device list. Release it */pcap_freealldevs (alldevs); return 1 ;}

Situation:

[1] It was originally a program used in Winpcap introduction. Due to the compatibility between Winpcap and libpcap, I got it under Ubuntu from Win32, and of course there were also changes:

The pcap_findalldevs function has added _ ex and you know what I mean in Win32, but it is shown in the preceding figure in Libpcap.

[2] Run the GCC-O getdevs. C-lpcap command to run OK. The./getdevs command also displays the NIC and description;

[3] The problem is: I put the source code in the C Project of eclipse, and it won't work (I have never used it before). I have learned this time.

You can click pcap. h In the source file to link to the header file, but the related functions and variables below indicate undefined reference.

Of course, we can see that there is also a parameter-lpcap in the GCC compilation above, but how can we add this parameter in eclipse?

You cannot directly add the file in run as.... The premise of running is that you need to build the file. Here, the build file cannot be used, that is, add the file to the project properties:

I will not talk about my individual hardships. I just want to talk about the answer:

I had the same problem in eclipse. I order to link this library to your project, right click the project in "project Explorer" (SHORT VIEW) and choose "properties ". on the left go to "C/C ++ build"> "Settings" and on the "Settings" Panel go to "tool Settings"
> "Gcc C linker" (if this is your compiler)> "Libraries"> and add the word "pcap" in the list titled "libraries (-l )". press "Apply" on the bottom and then "OK ". click "project"> "build all" and this shoshould do the job. it shoshould be no errors now.

Http://ubuntuforums.org/archive/index.php/t-125444.html thanks!

If you encounter the parameters required for this compilation, do you know to add them to it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.