net-snmp flags in CMAKE












0














Before anything, I just want to say I am very new to CMAKE, almost never used it but now forced to...



I am trying to include snmp features in a previous project, using Net-SNMP 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:



First, I must create object file:



gcc -I. `net-snmp-config --cflags`   -c -o tfsnmpset.o tfsnmpset.c


Then, I must generate the executable:



gcc -o tfsnmpset tfsnmpset.o `net-snmp-config --libs`


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 CMakeLists.txt to generate its makefile.



My question is, how do I include the following flags in my CMakeLists.txt?



When creating object files: `net-snmp-config --cflags` 
When generating executable: `net-snmp-config --libs`


I actually tried to build a library out of my code that uses Net-SNMP that I could just use in my main project:



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)


The errors:



/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









share|improve this question



























    0














    Before anything, I just want to say I am very new to CMAKE, almost never used it but now forced to...



    I am trying to include snmp features in a previous project, using Net-SNMP 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:



    First, I must create object file:



    gcc -I. `net-snmp-config --cflags`   -c -o tfsnmpset.o tfsnmpset.c


    Then, I must generate the executable:



    gcc -o tfsnmpset tfsnmpset.o `net-snmp-config --libs`


    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 CMakeLists.txt to generate its makefile.



    My question is, how do I include the following flags in my CMakeLists.txt?



    When creating object files: `net-snmp-config --cflags` 
    When generating executable: `net-snmp-config --libs`


    I actually tried to build a library out of my code that uses Net-SNMP that I could just use in my main project:



    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)


    The errors:



    /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









    share|improve this question

























      0












      0








      0


      0





      Before anything, I just want to say I am very new to CMAKE, almost never used it but now forced to...



      I am trying to include snmp features in a previous project, using Net-SNMP 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:



      First, I must create object file:



      gcc -I. `net-snmp-config --cflags`   -c -o tfsnmpset.o tfsnmpset.c


      Then, I must generate the executable:



      gcc -o tfsnmpset tfsnmpset.o `net-snmp-config --libs`


      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 CMakeLists.txt to generate its makefile.



      My question is, how do I include the following flags in my CMakeLists.txt?



      When creating object files: `net-snmp-config --cflags` 
      When generating executable: `net-snmp-config --libs`


      I actually tried to build a library out of my code that uses Net-SNMP that I could just use in my main project:



      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)


      The errors:



      /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









      share|improve this question













      Before anything, I just want to say I am very new to CMAKE, almost never used it but now forced to...



      I am trying to include snmp features in a previous project, using Net-SNMP 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:



      First, I must create object file:



      gcc -I. `net-snmp-config --cflags`   -c -o tfsnmpset.o tfsnmpset.c


      Then, I must generate the executable:



      gcc -o tfsnmpset tfsnmpset.o `net-snmp-config --libs`


      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 CMakeLists.txt to generate its makefile.



      My question is, how do I include the following flags in my CMakeLists.txt?



      When creating object files: `net-snmp-config --cflags` 
      When generating executable: `net-snmp-config --libs`


      I actually tried to build a library out of my code that uses Net-SNMP that I could just use in my main project:



      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)


      The errors:



      /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






      gcc cmake static-libraries compiler-flags






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 10:18









      PhoenixBlue

      417313




      417313





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409844%2fnet-snmp-flags-in-cmake%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409844%2fnet-snmp-flags-in-cmake%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'