bebbo / amiga-gcc

The GNU C-Compiler with Binutils and other useful tools for cross development for Amiga
GNU General Public License v2.0
312 stars 66 forks source link

If toolchain is built with THREADS=posix how do we compile the minimum example #292

Closed toptan closed 2 years ago

toptan commented 2 years ago

According to posix threads the minimal example is compiled like:

$CC -pthread test.c

However I get crazy error:

m68k-amigaos-gcc: error: unrecognized command line option '-pthread'; did you mean '-pthread'?

I also tried to do "direct" static lib link:

/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: /opt/amiga/m68k-amigaos/lib/libpthread.a(pthread.o): in function `_pthread_cond_timedwait.part.3':
pthread.o:(.text+0x1a02): undefined reference to `gettimeofday'
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: pthread.o:(.text+0x1a12): undefined reference to `timersub'
collect2: error: ld returned 1 exit status

Adding libnix into the story makes things even worse.

Toolchain compiled from master with THREADS=posix make all

Test code is:

[root@98c870bd6da5 ~]# cat test.c 
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

int main()
{
        pthread_t thread1, thread2;
        char *message1 = "Thread 1";
        char *message2 = "Thread 2";
        int  iret1, iret2;

        /* Create independent threads each of which will execute function */

        iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
        iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);

        /* Wait till threads are complete before main continues. Unless we  */
        /* wait we run the risk of executing an exit which will terminate   */
        /* the process and all threads before the threads have completed.   */

        pthread_join( thread1, NULL);
        pthread_join( thread2, NULL); 

        printf("Thread 1 returns: %d\n",iret1);
        printf("Thread 2 returns: %d\n",iret2);
        return 0;
}

void *print_message_function( void *ptr )
{
        char *message;
        message = (char *) ptr;
        printf("%s \n", message);
}

Please advise.

bebbo commented 2 years ago
 m68k-amigaos-gcc -Os -noixemul test.c -o test

will compile and link it.

toptan commented 2 years ago

Thanks! I forgot about -noixemul.

However, now c++ compiler doesn't work. It produces binary but when run it it just does nothing. Just hangs. Even the simplest example:

root@00e43cd3c0c0:~# cat minimal.cpp 
#include <iostream>

int main() {
        std::cout << "Hello world!" << std::endl;
        return 0;
}

compiled with m68k-amigaos-g++ -noixemul -Os -o minimal minimal.cpp just hangs...

bebbo commented 2 years ago

libpthread was initialized too late.

make update -j
make libpthread

and rebuild the program

toptan commented 2 years ago

@bebbo All good now. I will close this issue. Thank you for this great work!