0

I have downloaded SNMP++ 3.4.9 library and copied it to my project's directory (where my project name is SNMP)

So my directory looks like this:

>snmp++-3.4.9    [Folder]
    >Include            [Sub-Folder]
    >Examples           [Sub-Folder]
    libsnmp.h      
CMakeLists.txt
main.cpp

Inside main.cpp I have pasted a code example that uses the library like this (first few lines):

#include <libsnmp.h>
#include "snmp_pp/snmp_pp.h"
...

When I try to run the code it won't work, I get:

[1/2] Building CXX object CMakeFiles/SNMP.dir/main.cpp.o
FAILED: CMakeFiles/SNMP.dir/main.cpp.o 
.../XcodeDefault.xctoolchain/usr/bin/c++  -I/snmp++-3.4.9 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -std=gnu++14 -MD -MT CMakeFiles/SNMP.dir/main.cpp.o -MF CMakeFiles/SNMP.dir/main.cpp.o.d -o CMakeFiles/SNMP.dir/main.cpp.o -c /Users/john/CLionProjects/SNMP/main.cpp
/Users/john/CLionProjects/SNMP/main.cpp:28:10: fatal error: 'libsnmp.h' file not found
#include <libsnmp.h>
         ^~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

Someone suggested changing my CMakeLists.txt file to something like this:

cmake_minimum_required(VERSION 3.21)
project(SNMP)

set(CMAKE_CXX_STANDARD 11)
include_directories("/snmp++-3.4.9")

add_executable(SNMP main.cpp)

But still same problem, how can I fix this?

Please Note: From a previous understanding I had with C++ I don't get it why they wrote:

#include <libsnmp.h>

and not:

#include "libsnmp.h"

As It's not a standard library, and changing every instance from <> to "" will take a very long time (and doesn't sound the right thing to do)

I'm using CLion and working on macOS.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
John
  • 1
  • 2
  • If anyone is interested you can download it from: https://agentpp.com/download/snmp++-3.4.9.tar.gz – John Mar 06 '22 at 22:01
  • I'm not sure, but isn't `include_directories("/snmp++-3.4.9")` pointing to directory under root and not in your project directory? Try without that slash in the beginning – Yksisarvinen Mar 06 '22 at 22:03
  • @Yksisarvinen Did that and same problem. It seems with and without slash we are referring to project directory as in both cases CLion shows me files under `snmp++-3.4.9` folder (autocomplete) – John Mar 06 '22 at 22:10
  • Edited my question to show where `libsnmp.h` is located. – John Mar 06 '22 at 22:18
  • "It seems with and without slash we are referring to project directory" - No, this is wrong. In the build log you could clearly see, that your directory is passed to the compiler "as is", and since it is the **absolute path** (starts with slash), it can be only interpreted as a root directory of your machine. Instead, pass **correct absolute path** to the `include_directories` command. For refer to the directory where `CMakeLists.txt` is located, use `${CMAKE_CURRENT_SOURCE_DIR}`. – Tsyvarev Mar 06 '22 at 23:06
  • 4
    Please don't vandalize your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (_i.e._ regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed, and thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work](https://stackoverflow.com/help/what-to-do-instead-of-deleting-question)? – Henry Ecker Mar 07 '22 at 17:54
  • 1
    Don't vandalize the question. If you want it deleted, just vote to delete. It's a link under the question – Machavity Mar 07 '22 at 17:55

0 Answers0