关于uvc_streamer编译出错

gcc test.c -lpthread

在编译uvc_streamer的时候,会出现错误,

gcc -O2 -DLINUX -Wall -lpthread uvc_stream.o color.o utils.o v4l2uvc.o control.o -o uvc_stream 
uvc_stream.o: In function `main':
uvc_stream.c:(.text.startup+0x4ce): undefined reference to `pthread_create'
uvc_stream.c:(.text.startup+0x4da): undefined reference to `pthread_detach'
uvc_stream.c:(.text.startup+0x53d): undefined reference to `pthread_create'
uvc_stream.c:(.text.startup+0x549): undefined reference to `pthread_detach'
uvc_stream.c:(.text.startup+0x5d7): undefined reference to `pthread_create'
uvc_stream.c:(.text.startup+0x5e3): undefined reference to `pthread_detach'
collect2: ld returned 1 exit status
make: *** [uga_buga] Error 1

一看就知道是因为没有链接平pthread库了,查看Makefile,却出现了怪异的事情了

CC=gcc
APP_BINARY=uvc_stream


CFLAGS += -O2 -DLINUX -Wall
LFLAGS += -lpthread

OBJECTS=uvc_stream.o color.o utils.o v4l2uvc.o control.o

all: uga_buga

clean:
    @echo "Cleaning up directory."
    rm -f *.a *.o $(APP_BINARY) core *~ log errlog *.avi

# Applications:
uga_buga: $(OBJECTS)
    $(CC) $(CFLAGS) $(LFLAGS) $(OBJECTS) -o $(APP_BINARY) 
    chmod 755 $(APP_BINARY)

# useful to make a backup "make tgz"
tgz: clean
    mkdir -p backups
    tar czvf ./backups/uvc_streamer_`date +"%Y_%m_%d_%H.%M.%S"`.tgz --exclude backups *
明显就包含了嘛,为什么不对呢,后面怀疑是不是因为程序没有调用库,就自己写了个简单的多线程实例test.c,如下

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

pthread_t ntid;

void printids(const char *s) 
{
        pid_t pid;
        pthread_t tid;

        pid = getpid();
        tid = pthread_self();

        printf("%s pid %u tid %u (0x%x)\n", s,\ 
                        (unsigned int)pid, (unsigned int)tid, (unsigned int)tid); 
}

void *thr_fn(void *arg)
{
        printids ("new thread:");
        return ((void *)0);
}

int main(void)
{
        int err;

        err = pthread_create(&ntid, NULL, thr_fn, NULL);
        if (err != 0)
        {   
                printf ("can't create thread: %d\n", strerror(err));
        }   

        printids ("main thread:");

        sleep (1);
        exit (0);
} 


执行如下:

$ gcc test.c -lpthread

成功编译了,生成了一个a.out文件,执行了结果为

main thread: pid 5511 tid 3076396736 (0xb75e16c0)
new thread: pid 5511 tid 3076393792 (0xb75e0b40)
这下子可把我郁闷了。好吧!

先不管太多了,再看看Makefile是不是和其他的一样,我去查看了mjpg-streamer的Makefile,也没什么差别啊?

后面我就试试的态度,将

 $(CC) $(CFLAGS) $(LFLAGS) $(OBJECTS) -o $(APP_BINARY)
化成了

 $(CC) $(CFLAGS)  $(OBJECTS) -o $(APP_BINARY) $(LFLAGS)
神奇了,竟然编译成功了。


还不知道为什么,要继续查找资料了!

 
 





你可能感兴趣的:(thread,多线程,Stream,gcc,reference,makefile)