Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

which include dir is our lib

I did what hippo say in the forum,and get buildroot , linux-2.6.x ,apps and uClinux-dist.

I copied a C source program and named it as mu.It is like:

#include <stddef.h># include <stdio.h># include <unistd.h># include </home/melvin/buildroot/build_nios2/staging_dir/include/pthread.h>
void * process(void * arg)
{
  int i;
  fprintf(stderr, "Starting process %s\n", (char *) arg);
  for (i = 0; i < 10000; i++) {
    write(1, (char *) arg, 1);
  }
  return NULL;
}
int main(void)
{
  int retcode;
  pthread_t th_a, th_b;
  void * retval;
  retcode = pthread_create(&th_a, NULL, process, (void *) "a");
  if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
  else fprintf(stderr, "create a succeeded %d\n", retcode);
  retcode = pthread_create(&th_b, NULL, process, (void *) "b");
  if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
  else fprintf(stderr, "create b succeeded %d\n", retcode);
  retcode = pthread_join(th_a, &retval);
  if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
  else fprintf(stderr, "join a succeeded %d\n", retcode);
  retcode = pthread_join(th_b, &retval);
  if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
  else fprintf(stderr, "join b succeeded %d\n", retcode);
  return 0;
}

then

$ nios2-linux-uclibc-gcc mu.c -o mu -elf2flt -lm
mu.elf2flt(.text+0xe8): In function `main&#39;:
: undefined reference to `pthread_create&#39;
mu.elf2flt(.text+0x144): In function `main&#39;:
: undefined reference to `pthread_create&#39;
mu.elf2flt(.text+0x190): In function `main&#39;:
: undefined reference to `pthread_join&#39;
mu.elf2flt(.text+0x1dc): In function `main&#39;:
: undefined reference to `pthread_join&#39;
collect2: ld returned 1 exit status

why?

Can sb tell me where our app should be creat ed? And which include dir is our library?

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    try

    use# include <pthread.h> in your program.

    and

    add -lpthread to the compile command.