3 Replies Latest reply on Jan 1, 2016 9:46 AM by CABrouwers

    pthread on edison - undefined reference to symbol?

    CABrouwers

      I am using the Eclipse IDE.

      I have been trying to use the pthread library and I am getting a linker error:

      ... undefined reference to symbol 'pthread_create@@GLIBC_2.1'

      (i have tried on two different eclipse installations on two different machines with the same result)

      Any idea ?

      ...

        • 1. Re: pthread on edison - undefined reference to symbol?
          CMata_Intel

          Hi CABrouwers,

           

          Which Eclipse IDE version are you using?

          Which code are you using?

          Could you post a screenshot of the entire error message?

           

          I’m using Eclipse Version: Luna SR2 (4.4.2) (Help > About Eclipse Platform)

          Edison image version: 159.devkit (configure_edison --version)

           

          I’m using the following example and had no problems:

           

          #include <pthread.h>
          #include <stdio.h>
          #define NUM_THREADS    5
          
          void *PrintHello(void *threadid)
          {
            long tid;
            tid = (long)threadid;
            printf("Hello World! It's me, thread #%ld!\n", tid);
            pthread_exit(NULL);
          }
          
          int main (int argc, char *argv[])
          {
            pthread_t threads[NUM_THREADS];
            int rc;
            long t;
            for(t=0; t<NUM_THREADS; t++){
                printf("In main: creating thread %ld\n", t);
                rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
                if (rc){
                  printf("ERROR; return code from pthread_create() is %d\n", rc);
                }
            }
            /* Last thing that main() should do */
            pthread_exit(NULL);
          }
          
          

           

          Then I added the linker flag –pthread. By doing right click on the project > Properties > C/C++ Build > Settings > Cross GCC Linker > Miscellaneous and adding –pthread on Linker flags. After this, click on Apply and OK.

          pthreadflag.JPG

           

          Let me know if this works for you.

           

          Regards,

          Charlie

          • 2. Re: pthread on edison - undefined reference to symbol?
            CABrouwers

            Thanks for response.

            I copies the code in a new project and set the linker flag as you indicated.

            Now, I get the following error message:

             

            The program file specified in the launch configuration does not exist

            C:\Users\xxxxxx\workspace_iot\Testhread\Debug\Testhread not found

             

            I will do further test later ... but perhaps you have idea now  ?

             

            Happy New Year !

            • 3. Re: pthread on edison - undefined reference to symbol?
              CABrouwers

              Finally, I got it to work ! It took me a little while though.

              In order to avoid making a spelling error, i was copying the -pthread flag from your post.

              When I built I would get a pop up error message:

              The program file specified in the launch configuration does not exist

              C:\Users\xxxxx\workspace_iot\test\Debug\test not found

              However, when I typed -pthread myself, everything turned out fine !

              I assume was unknowingly copying some hidden characters that confused the linker!

              (probably something that should be fixed in Eclipse)

              Thanks a lot for your help!