0

[Error] expected primary-expression before 'void' Compiler: TDM-GCC 4.6.1 64-bit on this code の修正方法

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

using namespace std;

#define NUM_THREADS     5

int main ()
{
pthread_t threads[NUM_THREADS];
int rc;
int i;
for( i=0; i < NUM_THREADS; i++ ){
  cout << "main() : creating thread, " << i << endl;
 **rc = pthread_create(&threads[i], NULL, void * (*threadid *PrintHello));**
  if (rc){
     cout << "Error:unable to create thread," << rc << endl;
     exit(-1);
  }
 }
pthread_exit(NULL);
}

void *PrintHello(void *threadid)
{
intptr_t tid;
  tid = (intptr_t) threadid;
   cout << "Hello World! Thread ID, " << tid << endl;
  pthread_exit(NULL);

  }

このエラーを修正するにはどうすればよいですか? 事前に感謝します!

編集!これが正確なコンパイラの苦情です

Compiler: TDM-GCC 4.6.1 64-bit
Executing  g++.exe...
g++.exe "C:\Users\Thomas\Documents\c++\stuff\threads.cpp" -o       "C:\Users\Thomas\Documents\c++\stuff\threads.exe"  -march=pentium2 -mtune=pentium2 -msse2 -   O2 -m32 -std=gnu++98 -pg -g3  -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-   mingw32\include"  -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc -m32 -pg -g3
C:\Users\Thomas\Documents\c++\stuff\threads.cpp: In function 'int main()':
C:\Users\Thomas\Documents\c++\stuff\threads.cpp:16:45: error: expected primary-expression before 'void'

Execution terminated


[Error] expected primary-expression before 'void' 

もう一度編集完全なエラーを追加し、エラーはこの行にあります

rc = pthread_create(&threads[i], NULL, void * (*threadid *PrintHello));

16 45 C:\Users\Thomas\Documents\c++\stuff\threads.cpp [Error] expected primary-expression before 'void' 

編集3

述べられた変更を行った後、彼の部分的な解決策を提供してくれたポールRに感謝します

Compiler: TDM-GCC 4.6.1 64-bit
Executing  g++.exe...
g++.exe "C:\Users\Thomas\Documents\c++\stuff\threads.cpp" -o "C:\Users\Thomas\Documents\c++\stuff\threads.exe"  -march=pentium2 -mtune=pentium2 -msse2 -O2 -m32 -std=gnu++98 -pg -g3  -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include"  -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc -m32 -pg -g3
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmingw32.a when searching for -lmingw32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingw32.a when searching for -lmingw32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmoldname.a when searching for -lmoldname
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmoldname.a when searching for -lmoldname
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmingwex.a when searching for -lmingwex
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingwex.a when searching for -lmingwex
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmsvcrt.a when searching for -lmsvcrt
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmsvcrt.a when searching for -lmsvcrt
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libgmon.a when searching for -lgmon
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libgmon.a when searching for -lgmon
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libadvapi32.a when searching for -ladvapi32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libadvapi32.a when searching for -ladvapi32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libshell32.a when searching for -lshell32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libshell32.a when searching for -lshell32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libuser32.a when searching for -luser32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libuser32.a when searching for -luser32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libkernel32.a when searching for -lkernel32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libkernel32.a when searching for -lkernel32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmingw32.a when searching for -lmingw32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingw32.a when searching for -lmingw32
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmoldname.a when searching for -lmoldname
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmoldname.a when searching for -lmoldname
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmingwex.a when searching for -lmingwex
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingwex.a when searching for -lmingwex
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmsvcrt.a when searching for -lmsvcrt
c:/program files (x86)/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.6.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmsvcrt.a when searching for -lmsvcrt
C:\Users\Thomas\AppData\Local\Temp\ccZIOBl3.o: In function `Z10PrintHelloPv':
C:/Users/Thomas/Documents/c++/stuff/threads.cpp:31: undefined reference to `_imp__pthread_exit'
C:\Users\Thomas\AppData\Local\Temp\ccZIOBl3.o: In function `main':
C:/Users/Thomas/Documents/c++/stuff/threads.cpp:17: undefined reference to `_imp__pthread_create'
C:/Users/Thomas/Documents/c++/stuff/threads.cpp:23: undefined reference to `_imp__pthread_exit'
collect2: ld returned 1 exit status

Execution terminated

他のアイデアをいただければ幸いです。

4

1 に答える 1

4

変化する:

rc = pthread_create(&threads[i], NULL, void * (*threadid *PrintHello));

に:

rc = pthread_create(&threads[i], NULL, PrintHello, NULL);

PrintHelloの前にのプロトタイプも追加する必要がありますmain

void *PrintHello(void *threadid);
于 2013-03-07T10:04:12.297 に答える