From: Rayne on
Hi all,
I'm new to VS, and I'm using Visual Studio .NET 2003.

I'm trying to write a program which uses pcap libraries. However, I
keep getting the following errors:

error LNK2019: unresolved external symbol __imp__inet_ntoa@4
referenced in function _got_packet
error LNK2019: unresolved external symbol __imp__ntohs@4 referenced in
function _got_packet
error LNK2019: unresolved external symbol _Search referenced in
function _got_packet
error LNK2019: unresolved external symbol _memcpy_s referenced in
function _got_packet

The function got_packet is implemented in A.c, and the function Search
is implemented in B.c. I also have corresponding header files A.h and
B.h.

A.h looks somewhat like this (irrelevant code removed):

#ifndef A_H
#define A_H

#include <WinSock2.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <string.h>
#include <strsafe.h>

#include "B.h"

void got_packet(u_char *user, const struct pcap_pkthdr *header, const
u_char *packet);

#endif /* A_H */

B.h looks somewhat like this (irrelevant code removed):

#ifndef B_H
#define B_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

__inline int Search( /* Function parameters */ );

#endif /* B_H */

Why am I getting these errors and how can I solve them?

Thank you!

Regards,
Rayne
From: Ulrich Eckhardt on
Rayne wrote:
> error LNK2019: unresolved external symbol __imp__inet_ntoa@4
> referenced in function _got_packet

The inet_ntoa function is part of WinSock. Look up that function at
msdn.microsoft.com. Close to the bottom you will see the header to include
for it and the library to link with.

The others are harder to comment on, since you chose not to provide the
code.

> __inline int Search( /* Function parameters */ );

Don't. Unless you think you know better than the compiler when to inline
(and you generally don't) or when you must use inline to avoid multiple
definitions, don't inline. The compiler does a pretty good job at that.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: Rayne on
On Nov 25, 5:14 pm, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> Rayne wrote:
> > error LNK2019: unresolved external symbol __imp__inet_ntoa@4
> > referenced in function _got_packet
>
> The inet_ntoa function is part of WinSock. Look up that function at
> msdn.microsoft.com. Close to the bottom you will see the header to include
> for it and the library to link with.
>
> The others are harder to comment on, since you chose not to provide the
> code.
>
> > __inline int Search( /* Function parameters */ );
>
> Don't. Unless you think you know better than the compiler when to inline
> (and you generally don't) or when you must use inline to avoid multiple
> definitions, don't inline. The compiler does a pretty good job at that.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Thanks. I added ws2_32.lib and took out the __inline from my Search
function, and the program ran successfully.