How to solve “Undefined reference to function” in Eclipse CDT?











up vote
0
down vote

favorite












I did setup a C project with Eclipse Photon (4.8.0) for developing a program for the ESP-32. I did configure the IDE according to this official setup instructions.



Flashing the ESP-32 works fine. But as soon as I try to include header files from a sub folder, I run into troubles. I have set up a very simple project to illustrate the issue. The project consists of main.c, base/test.h and base/test.c, whereas the test.h and test.c files only contain one function with the signature void function1(void);.



When I try to call function1() in main.c, I get this error in main.c:




Undefined reference to function1()




Please compare to the attached screenshot, where everything is depicted.



How to solve this issue?



enter image description here










share|improve this question


























    up vote
    0
    down vote

    favorite












    I did setup a C project with Eclipse Photon (4.8.0) for developing a program for the ESP-32. I did configure the IDE according to this official setup instructions.



    Flashing the ESP-32 works fine. But as soon as I try to include header files from a sub folder, I run into troubles. I have set up a very simple project to illustrate the issue. The project consists of main.c, base/test.h and base/test.c, whereas the test.h and test.c files only contain one function with the signature void function1(void);.



    When I try to call function1() in main.c, I get this error in main.c:




    Undefined reference to function1()




    Please compare to the attached screenshot, where everything is depicted.



    How to solve this issue?



    enter image description here










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I did setup a C project with Eclipse Photon (4.8.0) for developing a program for the ESP-32. I did configure the IDE according to this official setup instructions.



      Flashing the ESP-32 works fine. But as soon as I try to include header files from a sub folder, I run into troubles. I have set up a very simple project to illustrate the issue. The project consists of main.c, base/test.h and base/test.c, whereas the test.h and test.c files only contain one function with the signature void function1(void);.



      When I try to call function1() in main.c, I get this error in main.c:




      Undefined reference to function1()




      Please compare to the attached screenshot, where everything is depicted.



      How to solve this issue?



      enter image description here










      share|improve this question













      I did setup a C project with Eclipse Photon (4.8.0) for developing a program for the ESP-32. I did configure the IDE according to this official setup instructions.



      Flashing the ESP-32 works fine. But as soon as I try to include header files from a sub folder, I run into troubles. I have set up a very simple project to illustrate the issue. The project consists of main.c, base/test.h and base/test.c, whereas the test.h and test.c files only contain one function with the signature void function1(void);.



      When I try to call function1() in main.c, I get this error in main.c:




      Undefined reference to function1()




      Please compare to the attached screenshot, where everything is depicted.



      How to solve this issue?



      enter image description here







      c eclipse embedded eclipse-cdt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 23:27









      salocinx

      1,35753574




      1,35753574
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          This is not a compiler, but rather a linker error.



          Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.






          share|improve this answer




























            up vote
            1
            down vote













            Seems like you need to do proper linking.





            1. If you are linking with a library, you need to specify:




              • name of the library: ProjectSettingsC C++ GeneralPaths and SymbolsLibraries

              • where the linker should search for this library: ProjectSettingsC C++ GeneralPaths and SymbolsLibrary Paths

                See Note 1.




            2. If you are linking with object files, add those to:




              • ProjectSettingsC C++ BuildSettingsLinkerMiscellaneousOther objects




            Note 1:

            If your library name is for example libsomething.a, than you need to specify only something as the name; so omitt lib prefix, and .a suffix. If your library is not prefixed with lib, then you need to add its name prefixed with :, for example: something.a should be added as :something.a.






            share|improve this answer





















              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',
              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%2f53234543%2fhow-to-solve-undefined-reference-to-function-in-eclipse-cdt%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              This is not a compiler, but rather a linker error.



              Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.






              share|improve this answer

























                up vote
                2
                down vote













                This is not a compiler, but rather a linker error.



                Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  This is not a compiler, but rather a linker error.



                  Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.






                  share|improve this answer












                  This is not a compiler, but rather a linker error.



                  Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 11:51









                  tofro

                  4,250725




                  4,250725
























                      up vote
                      1
                      down vote













                      Seems like you need to do proper linking.





                      1. If you are linking with a library, you need to specify:




                        • name of the library: ProjectSettingsC C++ GeneralPaths and SymbolsLibraries

                        • where the linker should search for this library: ProjectSettingsC C++ GeneralPaths and SymbolsLibrary Paths

                          See Note 1.




                      2. If you are linking with object files, add those to:




                        • ProjectSettingsC C++ BuildSettingsLinkerMiscellaneousOther objects




                      Note 1:

                      If your library name is for example libsomething.a, than you need to specify only something as the name; so omitt lib prefix, and .a suffix. If your library is not prefixed with lib, then you need to add its name prefixed with :, for example: something.a should be added as :something.a.






                      share|improve this answer

























                        up vote
                        1
                        down vote













                        Seems like you need to do proper linking.





                        1. If you are linking with a library, you need to specify:




                          • name of the library: ProjectSettingsC C++ GeneralPaths and SymbolsLibraries

                          • where the linker should search for this library: ProjectSettingsC C++ GeneralPaths and SymbolsLibrary Paths

                            See Note 1.




                        2. If you are linking with object files, add those to:




                          • ProjectSettingsC C++ BuildSettingsLinkerMiscellaneousOther objects




                        Note 1:

                        If your library name is for example libsomething.a, than you need to specify only something as the name; so omitt lib prefix, and .a suffix. If your library is not prefixed with lib, then you need to add its name prefixed with :, for example: something.a should be added as :something.a.






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Seems like you need to do proper linking.





                          1. If you are linking with a library, you need to specify:




                            • name of the library: ProjectSettingsC C++ GeneralPaths and SymbolsLibraries

                            • where the linker should search for this library: ProjectSettingsC C++ GeneralPaths and SymbolsLibrary Paths

                              See Note 1.




                          2. If you are linking with object files, add those to:




                            • ProjectSettingsC C++ BuildSettingsLinkerMiscellaneousOther objects




                          Note 1:

                          If your library name is for example libsomething.a, than you need to specify only something as the name; so omitt lib prefix, and .a suffix. If your library is not prefixed with lib, then you need to add its name prefixed with :, for example: something.a should be added as :something.a.






                          share|improve this answer












                          Seems like you need to do proper linking.





                          1. If you are linking with a library, you need to specify:




                            • name of the library: ProjectSettingsC C++ GeneralPaths and SymbolsLibraries

                            • where the linker should search for this library: ProjectSettingsC C++ GeneralPaths and SymbolsLibrary Paths

                              See Note 1.




                          2. If you are linking with object files, add those to:




                            • ProjectSettingsC C++ BuildSettingsLinkerMiscellaneousOther objects




                          Note 1:

                          If your library name is for example libsomething.a, than you need to specify only something as the name; so omitt lib prefix, and .a suffix. If your library is not prefixed with lib, then you need to add its name prefixed with :, for example: something.a should be added as :something.a.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 at 13:34









                          Danijel

                          2,448124684




                          2,448124684






























                              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%2f53234543%2fhow-to-solve-undefined-reference-to-function-in-eclipse-cdt%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

                              Landwehr

                              Reims

                              Javascript gets undefined on array