相关疑难解决方法(0)

Linux中对pthread_create的未定义引用

我从网上从https://computing.llnl.gov/tutorials/pthreads/上摘下了以下演示

#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud)

但是当我在我的机器上编译它(运行Ubuntu Linux 9.04)时,我收到以下错误:

corey@ubuntu:~/demo$ gcc -o term term.c …
Run Code Online (Sandbox Code Playgroud)

c linux multithreading pthreads

349
推荐指数
9
解决办法
57万
查看次数

C:对地板的未定义参考

我在Ubuntu上使用Eclipse来编写/编译/运行C代码.我正在尝试构建我的项目.以下是Eclipse控制台中的输出.

22:18:31 **** Build of configuration Debug for project Project1 ****
make all 
Building file: ../project1.c
Invoking: GCC C Compiler
gcc -I/lib/i386-linux-gnu -O0 -g3 -Wall -c -fmessage-length=0 -pthread -lm -MMD -MP -MF"project1.d" -MT"project1.d" -o "project1.o" "../project1.c"
../project1.c: In function ‘main’:
../project1.c:146:6: warning: unused variable ‘this_thread_id’ [-Wunused-variable]
../project1.c: In function ‘_pre_init’:
../project1.c:126:1: warning: control reaches end of non-void function [-Wreturn-type]
Finished building: ../project1.c

Building file: ../scheduler.c
Invoking: GCC C Compiler
gcc -I/lib/i386-linux-gnu -O0 -g3 -Wall -c -fmessage-length=0 -pthread -lm -MMD -MP …
Run Code Online (Sandbox Code Playgroud)

c gcc eclipse-cdt math.h ubuntu-12.04

4
推荐指数
1
解决办法
9446
查看次数

Glib - 来自glib的任何未定义的引用?

我的S程序有问题.我需要用这个命令编译它:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 \
    -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wall -Wextra -g -std=c99 -lm *.c \
    -o generator1_1
Run Code Online (Sandbox Code Playgroud)

我有很多这样的错误消息:

/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:153: undefined reference to `g_hash_table_lookup'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:171: undefined reference to `g_hash_table_insert'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:172: undefined reference to `g_array_append_vals'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:179: undefined reference to `g_array_append_vals'
/tmp/ccVqEbsM.o: In function `main':
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:238: undefined reference to `g_hash_table_new_full'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:239: undefined reference to `g_hash_table_new_full'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:263: undefined reference to `g_hash_table_destroy'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:264: undefined reference to `g_hash_table_destroy'
/tmp/cc2UG2Wy.o: In function `fillVFile':
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/reader.c:47: undefined reference to `g_strdup'
/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/reader.c:51: undefined reference to `g_ptr_array_add'
/tmp/cctOiTOl.o: In function `calculRegles': …
Run Code Online (Sandbox Code Playgroud)

c glib

1
推荐指数
1
解决办法
3242
查看次数

标签 统计

c ×3

eclipse-cdt ×1

gcc ×1

glib ×1

linux ×1

math.h ×1

multithreading ×1

pthreads ×1

ubuntu-12.04 ×1