DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Can't get started: "no such file"... (http://www.daniweb.com/forums/thread229715.html)

pocku Oct 13th, 2009 1:26 am
Can't get started: "no such file"...
 
The codes our instructor provided for us has been giving me a "no such file" error message for the line #include <mutex.h> in the following code:

/*
 *  mutex.cpp
 *  scheduling
 *
 */

#include <mutex.h>

Mutex::Mutex()
{

}

Mutex::~Mutex()
{

}

int Mutex::Lock()
{

}

int Mutex::Unlock()
{

}

The mutex.h code it is referring to is here:

/*
 *  mutex.h
 *  scheduling
 *
 */

#ifndef MUTEX_H
#define MUTEX_H

#include<pthread.h>

class Mutex
{
private:
    pthread_mutex_t mutex;
   
public: 
    /** Initializing the mutex
    */
    Mutex();
   
    /** Destroy the mutex
    */
    ~Mutex();
   
    /** Acquire the lock
    * @return The return value of pthread_mutex_lock().
    */
    int Lock();
   
    /** Release the lock
    * @return The return value of pthread_mutex_unlock().
    */
    int Unlock();
};
#endif

I've double checked and both codes are in the same directory and just in case you need to know, I am using Eclipse C/C++ and MinGW. Hopefully someone can help me out here so I can actually get started on this assignment!

dkalita Oct 13th, 2009 1:40 am
when u include a file in <> brace like follows
#include <mutex.h>
it looks in the include directory.
But your file mutex.h is in your current directory. To include such file u have to do it using ""
#include "mutex.h"

pocku Oct 13th, 2009 2:02 am
That sort of worked.... mutex.cpp doesn't have an error anymore but now I have an error message in mutex.h saying:

`pthread_mutex_t' does not name a type (on line 15)

as well as

pthread.h: no such file

Also, I forgot to mention that a Makefile is included with the codes as well but I don't know how to use it within Eclipse to build the codes. Do I need this Makefile or can I just build everything using eclipse?

firstPerson Oct 13th, 2009 3:06 am
How about you just ask your teacher since it will be easier and more straight forward.

dkalita Oct 13th, 2009 4:19 am
Quote:

Originally Posted by pocku (Post 1012660)
pthread.h: no such file

pthread.h is generally for POSIX systems like FreeBSD, NetBSD, GNU/Linux, Mac OS X and Solaris, but Microsoft Windows implementations also exist. For example, the pthreads-w32 is available and supports a subset of the Pthread API for the Windows 32-bit platform.

If you are working in windows it wont work. U have to look for
pthreads-w32 .

checkout the link
http://en.wikipedia.org/wiki/POSIX_Threads

pocku Oct 13th, 2009 3:10 pm
Quote:

Originally Posted by dkalita (Post 1012794)
pthread.h is generally for POSIX systems like FreeBSD, NetBSD, GNU/Linux, Mac OS X and Solaris, but Microsoft Windows implementations also exist. For example, the pthreads-w32 is available and supports a subset of the Pthread API for the Windows 32-bit platform.

If you are working in windows it wont work. U have to look for
pthreads-w32 .

checkout the link
http://en.wikipedia.org/wiki/POSIX_Threads

Thanks for pointing that out. I tired compiling it on my school's Linux computer and there wasn't a problem. I'm not sure whether our instructor is okay with us using pthreads-w32 so I'll have to ask her about that...

Also, this is for another assignment but what about arpa/inet.h or sys/socket.h? Are those also only supported by unix-like systems?

Quote:

How about you just ask your teacher since it will be easier and more straight forward.
Yep, I'll be seeing her today.

dkalita Oct 14th, 2009 12:31 am
Quote:

Originally Posted by pocku (Post 1013387)
Also, this is for another assignment but what about arpa/inet.h or sys/socket.h? Are those also only supported by unix-like systems?

Yes.

pocku Oct 15th, 2009 5:59 pm
Quote:

Originally Posted by dkalita (Post 1013751)
Yes.

Alright, thanks for letting me know!


All times are GMT -4. The time now is 3:04 am.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC