title: net-snmp flags in CMAKE
body: <p>Before anything, I just want to say I am very new to <code>CMAKE</code>, almost never used it but now forced to...</p>
  
  <p>I am trying to include snmp features in a previous project, using <code>Net-SNMP</code> library. But first, I wrote a minimalistic code just to test my functions. According to the library tutorial, this is how I must compile the code:</p>
  
  <p>First, I must create object file:</p>
  
  <pre><code>gcc -I. `net-snmp-config --cflags`   -c -o tfsnmpset.o tfsnmpset.c
  </code></pre>
  
  <p>Then, I must generate the executable:</p>
  
  <pre><code>gcc -o tfsnmpset tfsnmpset.o `net-snmp-config --libs`
  </code></pre>
  
  <p>By doing this, the program compiles perfectly and everything is fine. 
  Now the project in which I want to incorporate that piece of code uses <code>CMakeLists.txt</code> to generate its makefile.</p>
  
  <p>My question is, how do I include the following flags in my <code>CMakeLists.txt</code>?</p>
  
  <pre><code>When creating object files: `net-snmp-config --cflags` 
  When generating executable: `net-snmp-config --libs`
  </code></pre>
  
  <p>I actually tried to build a library out of my code that uses <code>Net-SNMP</code> that I could just use in my main project:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.12)
  project(snmp_daemon C)
  
  set(CMAKE_C_STANDARD 99)
  SET(CMAKE_C_COMPILER /usr/bin/gcc)
  set(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -I. `net-snmp-config --cflags`" )
  add_library(tfsnmpset tfsnmp.c tfsnmp.h)
  add_executable(snmp_daemon main.c ./tfsnmp.h)
  target_link_libraries(snmp_daemon tfsnmpset)
  </code></pre>
  
  <p>The errors: </p>
  
  <pre><code>/media/user/xtra/apps/clion-2018.2.1/bin/cmake/linux/bin/cmake --build /home/fabrice/projects/snmp-daemon/cmake-build-debug --target snmp_daemon -- -j 2
  [ 25%] Linking C static library libtfsnmpset.a
  [ 50%] Built target tfsnmpset
  [ 75%] Linking C executable snmp_daemon
  libtfsnmpset.a(tfsnmp.c.o): In function `tfsnmpset':
  /home/user/projects/snmp-daemon/tfsnmp.c:121: undefined reference to `snmp_parse_args'
  /home/user/projects/snmp-daemon/tfsnmp.c:147: undefined reference to `snmp_get_do_debugging'
  /home/user/projects/snmp-daemon/tfsnmp.c:147: undefined reference to `debugmsgtoken'
  /home/user/projects/snmp-daemon/tfsnmp.c:147: undefined reference to `debugmsg'
  /home/user/projects/snmp-daemon/tfsnmp.c:147: undefined reference to `debugmsgtoken'
  /home/user/projects/snmp-daemon/tfsnmp.c:147: undefined reference to `debugmsg'
  /home/user/projects/snmp-daemon/tfsnmp.c:194: undefined reference to `snmp_open'
  /home/user/projects/snmp-daemon/tfsnmp.c:199: undefined reference to `snmp_sess_perror'
  /home/user/projects/snmp-daemon/tfsnmp.c:207: undefined reference to `snmp_pdu_create'
  /home/user/projects/snmp-daemon/tfsnmp.c:210: undefined reference to `snmp_parse_oid'
  /home/user/projects/snmp-daemon/tfsnmp.c:211: undefined reference to `snmp_perror'
  /home/user/projects/snmp-daemon/tfsnmp.c:214: undefined reference to `snmp_add_var'
  /home/user/projects/snmp-daemon/tfsnmp.c:216: undefined reference to `snmp_perror'
  /home/user/projects/snmp-daemon/tfsnmp.c:222: undefined reference to `snmp_close'
  /home/user/projects/snmp-daemon/tfsnmp.c:230: undefined reference to `snmp_synch_response'
  /home/user/projects/snmp-daemon/tfsnmp.c:236: undefined reference to `print_variable'
  /home/user/projects/snmp-daemon/tfsnmp.c:239: undefined reference to `snmp_errstring'
  /home/user/projects/snmp-daemon/tfsnmp.c:247: undefined reference to `fprint_objid'
  /home/user/projects/snmp-daemon/tfsnmp.c:257: undefined reference to `snmp_sess_perror'
  /home/user/projects/snmp-daemon/tfsnmp.c:262: undefined reference to `snmp_free_pdu'
  /home/user/projects/snmp-daemon/tfsnmp.c:263: undefined reference to `snmp_close'
  collect2: error: ld returned 1 exit status
  CMakeFiles/snmp_daemon.dir/build.make:84: recipe for target 'snmp_daemon' failed
  make[3]: *** [snmp_daemon] Error 1
  CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/snmp_daemon.dir/all' failed
  make[2]: *** [CMakeFiles/snmp_daemon.dir/all] Error 2
  CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/snmp_daemon.dir/rule' failed
  make[1]: *** [CMakeFiles/snmp_daemon.dir/rule] Error 2
  Makefile:118: recipe for target 'snmp_daemon' failed
  make: *** [snmp_daemon] Error 2
  </code></pre>