2

I'm trying to write a simple demo application in C++. I just want to query some of the printers on my network and sort the incoming info into a few database tables but I get this error when compiling my code:

Error 1 error LNK2028: unresolved token (0A00001C) "extern "C" unsigned long __stdcall SnmpCleanup(void)" (?SnmpCleanup@@$$J10YGKXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) C:\Users\Ashton\Documents\Visual Studio 2010\Projects\snmpdemo\snmpdemo\Main.obj

My code is as follows:

//#include <Snmp.h>
#include <WinSnmp.h>
#include <stdio.h>

smiLPUINT32 majorVers;
smiLPUINT32 minorVers;
smiLPUINT32 nLevel;
smiLPUINT32 translateMode;
smiLPUINT32 retranslateMode;

int main()
{

    SnmpStartup(majorVers, minorVers, nLevel, translateMode, retranslateMode);

    printf("%imajorVers /n %iminorVers /n "
           "%inLevel /n "
           "%itranslateMode /n "
           "%iretranslateMode");

    SnmpCleanup();
}
greatwolf
  • 20,287
  • 13
  • 71
  • 105
Ashton
  • 81
  • 3
  • 11

1 Answers1

2

You do not have any definition for SnmpStartup() & SnmpCleanup() so linker complains that it cannot find a reference to it. Probably, you are using a library which defines these functions but are you linking to it?

EDIT:

You should be linking your program to Wsnmp32.lib or Wsnmp32.dll and it should work fine.
Have a look at this.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • how do i link to a DLL or LIB file? – Ashton Jul 08 '11 at 20:05
  • @Ashton: Add "snmp32.lib" to your library dependencies (Project Properties > Linker > Input > Additional Dependencies). That tells the linker where to find the code for the functions. – Alok Save Jul 08 '11 at 20:15
  • Im in visual studio 2010, & i dont see a linker option under the project properties. am i doing something wrong? – Ashton Jul 08 '11 at 20:20
  • @Ashton: I will suggest you to first understand what is a lib, what is a dll, what are the differences between them and how to use them with visual studio, Please search the internet and you will find number of explanations and tutorials..Unless you know the basic its hard to help you. – Alok Save Jul 08 '11 at 20:25
  • Ive linked the DLL but now its telling me : Error 1 error LNK1104: cannot open file 'C:\Windows\System32\wsnmp.dll' – Ashton Jul 08 '11 at 21:02
  • @Ashton: You need to add a path somewhere in settings, which will tell the linker where to pick the dll for linking, then you should keep the dll at that location. – Alok Save Jul 08 '11 at 21:21