Thread: Compile help

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    70

    Compile help

    It's me again

    When i compile i get this undefined reference to semWait

    I don't know if the problem is with my make file or code.

    Compiler:

    gcc -lpthread -o pctest pctest.o circbuffer.o
    circbuffer.o: In function `get_buffer':
    circbuffer.c.text+0xc0): undefined reference to `semWait'

    Code:
    all: hello sync sematest mutextest pctest
    
    hello: hello.c
            gcc -lpthread -o hello hello.c
    
    sync: sync.c
            gcc -lpthread -o sync sync.c
    
    sematest: sematest.o sema.o
            gcc -lpthread -o sematest sematest.o sema.o
    
    sema.o: sema.c sema.h
            gcc -Wall -c -o sema.o sema.c
    
    sematest.o: sematest.c
            gcc -Wall -c -o sematest.o sematest.c
    
    mutextest: mutextest.c
            gcc -lpthread -o mutextest mutextest.c
    
    pctest: pctest.o circbuffer.o
            gcc -lpthread -o pctest pctest.o circbuffer.o
    
    pctest.o: pctest.c
            gcc -Wall -c -o pctest.o pctest.c
    
    circbuffer.o: circbuffer.c circbuffer.h
            gcc -Wall -c -o circbuffer.o circbuffer.c
    circbuffer.c

    Code:
    #include "circbuffer.h"
    
    void init_buffer(bufferQueue *b, int min, int max)
    {
            b = malloc(sizeof(bufferQueue));
            b->buffer_array = malloc(max*sizeof(int));
            b->in = 0;
            b->out = 0;
            b->min_buffer_size = min;
            b->max_buffer_size = max;
    }
    
    bufferQueue *destroy_buffer(bufferQueue *b)
    {
            free(b);
            return b;
    }
    
    void put_buffer(bufferQueue *b, semaphore s, int v)
    {
            if((b->in+1)%b->max_buffer_size == b->out)
            {
                    //semWait(&s);
            }
    
            b->buffer_array[b->in] = v;
            b->in = (b->in+1)%b->max_buffer_size;
            }
    
    int get_buffer(bufferQueue *b, semaphore s)
    {
            if(b->in == b->out)
            {
                    semWait(&s);
            }
            return b->buffer_array[b->out];
            b->out = (b->out+1)%b->max_buffer_size;
    }
    circbuffer.h

    Code:
    #include "sema.h"
    #include <stdlib.h>
    
    typedef struct bufferQueue
    {
            int *buffer_array;
            int min_buffer_size;
            int max_buffer_size;
            int in;
            int out;
    } bufferQueue;
    
    void init_buffer(bufferQueue *b,int min, int max);
    bufferQueue *destroy_buffer(bufferQueue *b);
    void put_buffer(bufferQueue *b, semaphore s, int v);
    int get_buffer(bufferQueue *b, semaphore s);

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Where is the function semWait defined at?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    70
    semWait is defined in sema.c and the function prototype is in sema.h

    sema.h
    Code:
    #include <pthread.h>
    
    typedef struct semaphore
    {
    
            char buffer[100];
            int count;
            pthread_cond_t got_request;
            pthread_mutex_t request_mutex;
    
    } semaphore;
    
    semaphore init_sem(semaphore *s);
    semaphore destroy_sem(semaphore *s);
    void semWait(semaphore *s);
    void semSignal(semaphore *s);

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then you need (at least) sema.o included in your last phase of linking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 02:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 01:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM