Newbie trying to use pthreads

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newbie trying to use pthreads

3,210 Views
mphillips
Contributor I

Hello,

 

Some of this may apply to using any user-supplied library and some of this may be particular to pthreads (http://sourceware.org/pthreads-win32/). Anyway, I'm trying to test out some sample pthreads code in CodeWarrior, and here's what happened:

 

1) I put the pthreads folder in the main CodeWarrior directory and #include in the header. When I tried to compile, I got errors like

 

Error : Undefined symbol: '__declspec(dllimport) _pthread_mutex_lock (__imp__pthread_mutex_lock)'
referenced from '_thread_function' in pthread_ex.c:12
referenced from '_main' in pthread_ex.c:31
pthread_ex.c line 12

 

2) I added pthread.c to the project (Project -> Add files). Then I got this error, followed by many errors relating to undefined data types, etc.:

 

Error : the file 'timeb.h' cannot be opened
(included from:
private.c:55
pthread.c:44)
ptw32_relmillisecs.c line 43 #include timeb.h>

 

3) So, I added timeb.h and cdefs.h from www.koders.com, and put these files in the 'sys' folder. The syntax errors relating to time structures remained, e.g.

 

Error : ';' expected
(included from:
private.c:55
pthread.c:44)
ptw32_relmillisecs.c line 50 const int64_t NANOSEC_PER_MILLISEC = 1000000;

 

Error : expression syntax error
(included from:
private.c:55
pthread.c:44)
ptw32_relmillisecs.c line 51 const int64_t MILLISEC_PER_SEC = 1000;

 

Error : expression syntax error
(included from:
private.c:55
pthread.c:44)
ptw32_relmillisecs.c line 52 DWORD milliseconds;

 


********************************************************************************
So, I'd be extremely grateful if anyone could shed some light on what's going on here for me. Are there more files I need to add? Have I accessed the pthreads library inappropriately? Thank you for your consideration--

 

Best,
Matt

Labels (1)
0 Kudos
3 Replies

761 Views
pittbull
Contributor III
Hi,
The Pthreads lib you try to use seems to be made for MS Visual C++.
The '__declspec(dllimport)' is a MS-specific extensions to the C language.
I don't think there's a CW version of Pthreads, so you must port it yourself (Can't be that much difficult).

Anyway, Pthreads needs an underlying operating system that supports
native threading (But I think you already know that)...

Cheers,
-> pittbull
0 Kudos

761 Views
mphillips
Contributor I


pittbull wrote:
Hi,
The Pthreads lib you try to use seems to be made for MS Visual C++.
The '__declspec(dllimport)' is a MS-specific extensions to the C language.
I don't think there's a CW version of Pthreads, so you must port it yourself (Can't be that much difficult).

Anyway, Pthreads needs an underlying operating system that supports
native threading (But I think you already know that)...

Cheers,
-> pittbull




Thanks for your response to my query. I'm not quite sure about the relation of Visual C++ to Win32 and Windows XP, but in any case, the pthreads library I downloaded is the Win32 version and I'm running CW on Windows XP. Given this, is it still likely that there's an OS incompatibility? I've never ported anything before--do you have a favorite online tutorial for how to do this? Thanks--

Best,
Matt
0 Kudos

761 Views
pittbull
Contributor III
mphillips wrote:
>>I'm not quite sure about the relation of Visual C++ to Win32 and Windows XP

Most open source, freeware and commercial stuff for windoze is made with MS tools
like VC++6, VS2005 and so on. If you find codes on the web for Win32, they will (most
likely) compile with MS tools, but one must modify something to compile them with GCC, CW, etc.

mphillips wrote:
>>the pthreads library I downloaded is the Win32 version and I'm running CW on Windows XP.
>>Given this, is it still likely that there's an OS incompatibility?

No, it's a compiler incompatibility. MS compilers use '__declspec(dllimport)' to tell the compiler and linker that a function resides in a DLL. I don't know what CW for Win32 uses to do the same thing.

BTW: In my opinion, the PThread library is only necessary if you write multithreading-aware programs that must be portable across UNIX-like systems. Under Windows you can use WinApi functions like 'CreateThread'...

Cheers,
-> pittbull
0 Kudos