I need to create a basic program for work that utilizes the snmpget command. It needs to be usable in both windows and solaris as our clients use both. What's the best snmp library to use? I tried to download a number of them but I can't even get the sample programs that come with them to compile due to linker errors.

did you try this tutorial?

Please post a few of the link errors.

I know what snmp commands that I need to use, it's just a matter of getting a working library so that I can compile a C++ program that the clients could install to do an automatic diagnostic test rather than manually typing the commands at cmd prompt.

Anywho, I got past the linker errors its seems, but I'm getting others now. As of right now, I'm trying to get Agent++ and SNMP++ working. http://www.agentpp.com/snmp_pp3_x/snmp_pp3_x.html

The one problem that I'm running into however is that it says it's a windows and unix solution, but one of the header files from the install contains

#ifdef WIN32
#elif defined (CPU) && CPU == PPC603
#include <sys/times.h>
#else
#include <sys/time.h>
#include <sys/param.h>
#endif

and I'm getting the error:
fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory
which from the research I've done (which only involved googling sys/time.h), it seems as though that's a unix header. Like I said before, this program needs to work in both Solaris and Windows but for now I'm just developing in Windows.

I also get these 3 errors:
1>C:\snmp\snmp++\include\snmp_pp/config_snmp_pp.h(171) : error C2146: syntax error : missing ';' before identifier 'SnmpSocket'
1>C:\snmp\snmp++\include\snmp_pp/config_snmp_pp.h(171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\snmp\snmp++\include\snmp_pp/config_snmp_pp.h(171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

revolving around this section of code:

#ifdef _MSC_VER
    typedef SOCKET SnmpSocket;
#else
    typedef int SnmpSocket;
#endif

And then a number of other errors revolving around SnmpSocket usage which I'm assuming will disappear once this problem is fixed.

Like I said, this is in the header files included with their packaged product so it's not really any code that I've modified myself.

it does build on FreeBSD. and therefore should build on Solaris.
here is an extract of the make output.
as you can see from it, the Makefile does not have anything special.
are you using the wrong Makefile? or a different version of the library?

root@/usr/ports/net-mgmt/snmp++:#make
=> snmp++v3.2.22.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from http://www.agentpp.com/.
snmp++v3.2.22.tar.gz                          100% of  255 kB   76 kBps
===>  Extracting for snmp++-3.2.22_2
=> MD5 Checksum OK for snmp++v3.2.22.tar.gz.
=> SHA256 Checksum OK for snmp++v3.2.22.tar.gz.
/bin/cp /usr/ports/net-mgmt/snmp++/files/Makefile.FreeBSD /usr/ports/net-mgmt/snmp++/work/snmp++/src
===>  Patching for snmp++-3.2.22_2
===>  Applying FreeBSD patches for snmp++-3.2.22_2
===>   snmp++-3.2.22_2 depends on executable: gmake - found
===>  Configuring for snmp++-3.2.22_2
===>  Building for snmp++-3.2.22_2
g++ -D_XPG4_EXTENDED -D__unix -Wall -D_USE_OPENSSL -I../include -I./ -I../../libdes -I../../crypt/src/headers -g  -o address.o -c address.cpp
g++ -D_XPG4_EXTENDED -D__unix -Wall -D_USE_OPENSSL -I../include -I./ -I../../libdes -I../../crypt/src/headers -g  -o asn1.o -c asn1.cpp
// .. etc

I downloaded the files in that link but WinZip is not able to decompress then. The files have .tar.tar extension.

I'm really not sure to be honest. Here's the code that I'm using to try to test it. This code can be found in the rather outdated documentation for SNMP++. The OID and IP address are different in the documentation, but that shouldn't affect the compiling.

#include <snmp_pp_ext.h>
#include <iostream>
#define INPUT_ERRORS "1.3.6.1.2.1.2.2.1.14.1"                     //Object ID for the switch port's input errors
using namespace std;

int main()
{
      int status;                                                                   // return status
      CTarget ctarget( (IpAddress) "192.168.3.1");                // cisco switch target
      Vb vb(INPUT_ERRORS);                                                    // SNMP++ Variable Binding Object
      Pdu pdu;                                                                      // SNMP++ PDU

      // Construct a SNMP++ SNMP Object
      Snmp snmp(status);                                                            // Create a SNMP++ session
      if(status!=SNMP_CLASS_SUCCESS)                                          // Check Creation Status
      {
            cout <<< snmp.error_msg(status);                            // Print error string on fail
            return 0;
      }

      // Invoke a SNMP++ Get
      pdu +=vb;                                                                     // Add the variable binding to the PDU
      if (( status = snmp.get(pdu, ctarget))!= SNMP_CLASS_SUCCESS)
            cout << snmp.error_msg(status);
      else
      {
            pdu.get_vb(vb,0);                                                 // Extract the variable binding form PDU
            cout<<"Input Errors: "<<vb.get_printable_value();     // Print the Value
      }
      cout << "Test\n";

      return 0;
}

Yeah, I had to use Winrar in order to decompress the files.

are you having -D__unix -I <include dirs> etc in your Makefile. if not, you could perhaps copy the preprocessor defines and compiler switches from the Makefile which came with the tarball.

instead of -D__unix, you would probably require a -DWIN32 on windows. do you have it? and for lines like this one typedef SOCKET SnmpSocket; , you would probably need the platform SDK headers in your include path.

Do you need makefiles for a windows platform?

And as far as needing the Platform SDK headers in my include path, I set up the under Tools->Options->VC++ Directories->Include Files the directories linking to the include files in Visual Studio. Is this what you mean?

I feel so noobish. College definitely did not prepare me for my first Software Engineering Job. =X

> Do you need makefiles for a windows platform?
you need some kind of a makefile. if you are using Visual C++, the project / workspace files also act as makefiles. you could set the preprocessor defines (WIN32 etc) in the project properties from the IDE. if you do not know how to do this, just add a #define WIN32 as the first line of the file you are trying to compile. before #include <snmp_pp_ext.h> > And as far as needing the Platform SDK headers in my include path, I set up the under Tools->Options->VC++ Directories->Include Files the directories linking to the include files in Visual Studio. Is this what you mean?
yes, that should be fine then. but this

#ifdef _MSC_VER
    typedef SOCKET SnmpSocket;
#else
    typedef int SnmpSocket;
#endif

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int suggests that it is not there in your include path. perhaps also add a #define _WIN32_WINNT 0x0501 ?

To use SOCKET you have to include winsock.h when compiling for MS-Windows

>>I feel so noobish. College definitely did not prepare me for my first Software Engineering Job. =X

Now you have the life-long task of really learning. You ain't seen not'in yet :)

Ah, adding the #define WIN32 fixed all of the errors I had but now I'm once again getting all of the terrible linker errors.

25 Errors that are all either LNK2001 or LNK2019. Here's a few of the errors.

1>Network Health.obj : error LNK2001: unresolved external symbol "public: virtual class SnmpSyntax & __thiscall GenAddress::operator=(class SnmpSyntax const &)" (??4GenAddress@@UAEAAVSnmpSyntax@@ABV1@@Z)
1>Network Health.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall GenAddress::parse_address(char const *,enum Address::addr_type)" (?parse_address@GenAddress@@MAE_NPBDW4addr_type@Address@@@Z)
1>Network Health.obj : error LNK2019: unresolved external symbol "public: __thiscall GenAddress::GenAddress(class GenAddress const &)" (??0GenAddress@@QAE@ABV0@@Z) referenced in function "public: virtual class SnmpSyntax * __thiscall GenAddress::clone(void)const " (?clone@GenAddress@@UBEPAVSnmpSyntax@@XZ)
1>Network Health.obj : error LNK2019: unresolved external symbol "public: __thiscall Oid::Oid(class Oid const &)" (??0Oid@@QAE@ABV0@@Z) referenced in function "public: __thiscall Vb::Vb(class Oid const &)" (??0Vb@@QAE@ABVOid@@@Z)

Thanks a lot for the help thus far.


@AncientDragon - Yeah, especially since it's working with Nuclear Services for Westinghouse. Definitely didn't cover anything nuclear in nature during school. :confused:

the easiest fix would be to add the snmp++ library to your project. (the .lib file).

I downloaded the libdes.lb from the SNMP++ site and added it to my VC++ project but I still seem to be getting the linker errors. Do I need to do anything else besides this?

This is the first time I've worked with libraries. ><

i think you should look for a library with a name like libsnmp++.lib on unix, the libraries built are libsnmp++.a (static) and libsnmp++.so (shared). the one you have included is probably required too ( DES is an encryption standard).

i should have looked at the download page earlier. it does mention MS VC++7.0 Project Files http://www.agentpp.com/msvc7.zip perhaps you need to build the library from source. what does the README say?

I can't find any other libraries. Would I have to build them somehow by chance?

i think you would need to build the library from sources. (i can't test anything on windows; i'm on unix right now, and don't have a windows machine near me.). see what this is http://www.agentpp.com/msvc7.zip

I ran dynamicLIB.sln and staticLIB.sln and it created 2 XML files in the directories UpgradeLog.XML and UpgradeLog2.XML but no .lib files. Is this even what I was supposed to do? =P

ok. here is what you need to do.
download the following files:
http://www.agentpp.com/snmp++v3.2.23.tar.gz
http://www.agentpp.com/libdes-l-4.01a.tar.gz
http://www.agentpp.com/msvc7.zip
extract all three into the same directory (say C:\snmp_files)
your diectory structure now should be

snmp_files
         |
-------------------
|         |       |    
libdes   msvc    snmp++

open C:\snmp_files\msvc\static\snmp++\snmp++.vcproj in visual c++ ide
the project will need conversion (if you are using vc++ 2005 0r 2008),
let the ide convert it.

either add C:\snmp_files\libdes to your include path or
in C:\snmp_files\snmp++\src\auth_priv.cpp modify line 59
from #include <des.h> to #include "..\libdes\des.h" rebuild all.

the static library snmp++.lib would be created in
C:\snmp_files\msvc\static\debug (debug build)
C:\snmp_files\msvc\static\release (release build).

build other libraries in a similar fashion.

commented: Very Helpful +1

Thanks, I'll try that when I get back to work tomorrow and let you know how it works out.

I could use netsnmp from sourceforge successfully for unix.

I got these two errors when I tried to compile
C:\snmp_files\msvc\static\snmp++\snmp++.vcproj in visual c++ 2005.

1>..\..\..\snmp++\src\uxsnmp.cpp(719) : error C2065: 'm_hThread' : undeclared identifier
1>..\..\..\snmp++\src\uxsnmp.cpp(720) : error C2065: 'm_hThreadEndEvent' : undeclared identifier

Sigh, this is so frustrating that it's a prepackaged product and I can't get things to compile correctly.

EDIT - I fixed the problem. I forgot I had turned off thread support in one of the config files because we didn't want this program flooding the network with snmp requests so there was no need for threads, but I just turned it back on and it compiled.

Now to try the others... Thanks so far by the way.

I got the snmp++.lib to finally compile but it's only in the debug folder. Is this correct? My main program is still plagued with a bunch of linker errors.


The thing that sucks is our hardware supplier is already working on a fix or diagnostic program (I'm not sure which) for the media convertors which is what I'm creating a program to test. But since I'm still in training, my manager just wants me to mess around and see if I can get something working to refamiliarize myself with C++ and networking even though they won't ever use it.

Just throwing this out there as a suggestion:

Maybe C++ isn't the best option (You didn't mention this as a requirement).

If it's just a "basic program" perhaps a scripting language like python might be a better fit. I've never used it but there is the PySNMP library. If you don't have python experience, I suggest you learn it. If you know C++, it should be easy to pick up. It's often much quicker and better suited for little problems like these.

Yeah, there was a really basic PERL script that another guy here wrote a few months back which did the general thing that was wanted but since I've never worked with PERL I thought porting the script to C++ might be an easier alternative. Are PERL scripts compatible with Solaris? If so, maybe I'll just bite the bullet and try to edit his code to make it more functional. I'm assuming you can still write things to a file and such in PERL?

Yes to your questions about perl.

But I would really look into learning python. It comes in really handy for tasks like these. Like I said, if you know C++, you can be writing python code in no time (hours even). Google uses it extensively.

It doesn't hurt to be at least competent in perl, too, so I would consider editing his code.

commented: Suggested alternative to save time +1

Alright yeah, I'll probably just look into doing that and scrapping this whole snmp library thing. It's caused me nothing but problems since I've been trying to get a number of them working. =P

Thanks for your help guys, and advice.

I am not sure if someone is still looking at this thread.

I faced exactly the same problems discussed in the thread and followed the solutions. I could generate the snmp++.lib (in static) and snmp_pp.lib and snmp_pp.dll (in dynamic). I added them and compiled the sample program called ReceivedPower (the one mentioned in the thread) and it compiled successfully.

However when I am running it, I get the following error:

----------------------------------
ReceivedPower.exe - System Error
----------------------------------
The program can't start because snmp_pp.dll is missing from your computer. Try reinstalling the program to fix this problem.
---------------------------
OK
---------------------------

I couldn't find anyone mentioning this. Can someone please shed some light?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.