ich ein Programm mit POSIX-Threads mit gcc tun müssen, und wenn ich versuche, es zu kompilieren, zeigt das Terminal eine Meldung wie:Troubles mit POSIX-Programmthreads mit gcc
/tmp/ccw594wa.o: In Funktion main': POSIX.c:(.text+0xda): undefined reference to
pthread_create ' POSIX.c :(text + 0x102): undefined reference to `pthread_create' collect2: ld devolvió el estado de salida 1
mir jemand helfen kann die Fehlerursache ?? zu identifizieren, muss das Programm Implementieren des Producer-Consumer-Algorithmus, um eine Aufgabe zu erledigen, ist mein Code (unvollendet) der nächste
#include "stdio.h"
#include "pthread.h"
#define p printf
#define s scanf
pthread_mutex_t exmut;
float suma=0;
float x;
int iteraciones;
void *h_productor (void *arg) /*Procedimiento del productor*/
{
}
void *h_consumidor (void *arg) /*Procedimiento del consumidor*/
{
}
main() /*Hilo principal*/
{
int error;
int *out, idp=1, idc=2;
pthread_t productor; /*Hilo que realiza el proc. del productor*/
pthread_t consumidor; /*Hilo que realiza el proc. del consumidor*/
p ("\n\n Cálculo de e^x, por medio de una serie infinita... =)!");
p ("\n\n x= ");
s ("%f",&x);
do
{
p (" No. de iteraciones: ");
s ("%d",&iteraciones);
if (iteraciones<1 || iteraciones>10)
p("\n Número no válido, debes introducir un valor de entre 1 y 10\n");
}
while (iteraciones<1 || iteraciones>10);
pthread_mutex_init (&exmut, NULL);
/*Creamos ambos hilos, tanto el productor como el consumidor*/
error = pthread_create (&productor,NULL,h_productor,&idp);
error = pthread_create (&consumidor,NULL,h_consumidor,&idc);
/*
/*Esperamos a que ambos hilos terminen/
error = pthread_join (h_productor,(void **)&out);
error = pthread_join (h_consumidor,(void **)&out);
*/
p ("\n La aproximación para %d iteraciones del valor de e^%f= %f",iteraciones,x,suma);
}
Sie bedeutete '-lpthread'? –
@Pavan, nein, '-pthread' behandelt das (und ist portabler): http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling – huon
Nice. Danke :) –