C 使用pthread编译/链接错误

C 使用pthread编译/链接错误,c,linker,pthreads,linker-errors,C,Linker,Pthreads,Linker Errors,我试图制作一个小程序,使用线程对数组进行排序,但我无法使用线程支持对其进行编译 错误: sortieren.c:(.text+0xd7): undefined reference to `ptread_create' 为了便于编译,我使用了make文件,但在命令行中,我无法让它工作 基本代码: #include <pthread.h> int main(int argc, char **argv) { pthread_t threads[2]; // code sn

我试图制作一个小程序,使用线程对数组进行排序,但我无法使用线程支持对其进行编译

错误:

sortieren.c:(.text+0xd7): undefined reference to `ptread_create'
为了便于编译,我使用了make文件,但在命令行中,我无法让它工作

基本代码:

#include <pthread.h>
int main(int argc, char **argv) {
    pthread_t threads[2];
    // code snipped
    int ret = ptread_create(&threads[0], NULL, threadOne(), NULL);
    printf("ret: %d\n", ret);
    // code snipped
}
使用
make sortieren
生成此输出

gcc -pthread -c sortieren.c
gcc sortieren.o
sortieren.o: In function `main':
sortieren.c:(.text+0xd7): undefined reference to `ptread_create'
collect2: ld returned 1 exit status
make: *** [sortieren] Fehler 1
当然,我试着用谷歌搜索,但我找到的每一个“解决方案”都不适合我。我在make文件的任何地方都尝试了
-pthread
-lphread
。为了确保我的代码没有出错,我还尝试了:

更新

使用@Banthar提到的方法也不管用

$ make sortieren
gcc -c sortieren.c
gcc -lpthread sortieren.o
sortieren.o: In function `main':
sortieren.c:(.text+0xd7): undefined reference to `ptread_create'
collect2: ld returned 1 exit status
make: *** [sortieren] Fehler 1
应该是:

sortieren : sortieren.o
    gcc -lpthread sortieren.o

sortieren.o : sortieren.c 
    gcc -c sortieren.c

你的拼写错误,它是
pthread\u create()
,我想你在写
ptread\u create()

至少您的错误是这样说的:
未定义对ptread\u create的引用

,但在之后运行
gcc sortieren.o
会导致相同的错误。我编辑了我的答案。链接期间应添加库,例如
-lpthread
。例如,当您将
.o
文件合并到可执行文件中时。@WarrenFaith:gcc命令不会使用您的makefile。尝试
make sortieren
。您还有一个打字错误
ptread\u create
,而不是
pthread\u create
-lpthread和其他
-l
选项必须位于链接器命令行的末尾,而不是开头。尝试pthread\u create而不是ptread\u created这可能是一场灾难的重复!!应该是未声明的符号错误(由于打字错误),应该是由编译器本身引发的,它将通过编译阶段。。在链接的时候,链接者在抱怨!!!说真的,这是编译器不可接受的行为!!它位于以下行中:int ret=ptread_create(&threads[0],NULL,threadOne(),NULL);主要是你的
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
$ make sortieren
gcc -c sortieren.c
gcc -lpthread sortieren.o
sortieren.o: In function `main':
sortieren.c:(.text+0xd7): undefined reference to `ptread_create'
collect2: ld returned 1 exit status
make: *** [sortieren] Fehler 1
sortieren : sortieren.o
    gcc sortieren.o

sortieren.o : sortieren.c 
    gcc -pthread -c sortieren.c
sortieren : sortieren.o
    gcc -lpthread sortieren.o

sortieren.o : sortieren.c 
    gcc -c sortieren.c