954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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 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!

pocku
Newbie Poster
22 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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"
dkalita
Posting Pro in Training
402 posts since Sep 2009
Reputation Points: 121
Solved Threads: 61
 

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?

pocku
Newbie Poster
22 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

How about you just ask your teacher since it will be easier and more straight forward.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 
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 forpthreads-w32 .

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

dkalita
Posting Pro in Training
402 posts since Sep 2009
Reputation Points: 121
Solved Threads: 61
 

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?How about you just ask your teacher since it will be easier and more straight forward.

Yep, I'll be seeing her today.

pocku
Newbie Poster
22 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
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.

dkalita
Posting Pro in Training
402 posts since Sep 2009
Reputation Points: 121
Solved Threads: 61
 
Yes.

Alright, thanks for letting me know!

pocku
Newbie Poster
22 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You