2

Currently, I am studying Minix and I am doing a system based on threads and do not know how to compile my program.

For example: Mthreads.c

#include <stdlib.h>
#include <stdio.h>
#include <minix/mthread.h>

void hola(int y){
     printf("Hola Mundo");
}

int main(){

    mthread_thread_t a;

    mthread_create(&a, NULL, (void*)hola, 0);
    mthread_join(a, NULL);
}

Then I run clang to compile:

# clang Mthreads.c 
/var/tmp/g-10649b.o: In function `main':
Mthreads.c:(.text+0x5f): undefined reference to `mthread_create'
Mthreads.c:(.text+0x7d): undefined reference to `mthread_join'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any idea how to make this work?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • 3
    I never used minix however I can give you a hint: the error that you're getting is a linker error. The compiler was able to find the symbols "mthread_create" and "mthread_join" inside the header file: "minix/mthread.h" however it cannot find the implementation of these functions. Usually these will be in a c library (either static or dynamic). So you need to figure out where the minix libraries are and tell the linker to look for them with "-l" option in command line. – Uri Brecher Apr 28 '16 at 04:07
  • 1
    Possible duplicate of [Undefined reference to 'pthread\_create' — linker command option order (libraries before/after object files?)](http://stackoverflow.com/questions/9253200/undefined-reference-to-pthread-create-linker-command-option-order-libraries) – NathanOliver Dec 22 '16 at 16:48

1 Answers1

1

Use mthread library when compiling. Try it and you will solve your problem

clang Mthreads.c -lmthread
Polluks
  • 525
  • 2
  • 8
  • 19
msc
  • 33,420
  • 29
  • 119
  • 214
  • 1
    Do you mean `-pthread` as in the text or `-lpthread` as in the command line? Also, why `pthread` (which normally means POSIX threads) rather than `-lmthread` (which looks more natural to an outsider's eyes) or perhaps `-lthread`. – Jonathan Leffler Apr 28 '16 at 04:36
  • 1
    @JonathanLeffler: you guessed correctly, it should really be `-lmthread` in MINIX. – AntoineL Jun 12 '16 at 19:15