Using sem_t in a Qt Project
Posted
by thauburger
on Stack Overflow
See other posts from Stack Overflow
or by thauburger
Published on 2010-05-24T19:19:28Z
Indexed on
2010/05/24
20:01 UTC
Read the original article
Hit count: 560
Hi everyone,
I'm working on a simulation in Qt (C++), and would like to make use of a Semaphore wrapper class I made for the sem_t type.
Although I am including semaphore.h in my wrapper class, running qmake provides the following error:
'sem_t does not name a type'
I believe this is a library/linking error, since I can compile the class without problems from the command line.
I've read that you can specify external libraries to include during compilation. However, I'm a) not sure how to do this in the project file, and b) not sure which library to include in order to access semaphore.h.
Any help would be greatly appreciated.
Thanks,
Tom
Here's the wrapper class for reference:
Semaphore.h
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
#include <semaphore.h>
class Semaphore {
public:
Semaphore(int initialValue = 1);
int getValue();
void wait();
void post();
private:
sem_t mSemaphore;
};
#endif
Semaphore.cpp
#include "Semaphore.h"
Semaphore::Semaphore(int initialValue) {
sem_init(&mSemaphore, 0, initialValue);
}
int Semaphore::getValue() {
int value;
sem_getvalue(&mSemaphore, &value);
return value;
}
void Semaphore::wait() {
sem_wait(&mSemaphore);
}
void Semaphore::post() {
sem_post(&mSemaphore);
}
And, the QT Project File:
TARGET = RestaurantSimulation
TEMPLATE = app
QT +=
SOURCES += main.cpp \
RestaurantGUI.cpp \
RestaurantSetup.cpp \
WidgetManager.cpp \
RestaurantView.cpp \
Table.cpp \
GUIFood.cpp \
GUIItem.cpp \
GUICustomer.cpp \
GUIWaiter.cpp \
Semaphore.cpp
HEADERS += RestaurantGUI.h \
RestaurantSetup.h \
WidgetManager.h \
RestaurantView.h \
Table.h \
GUIFood.h \
GUIItem.h \
GUICustomer.h \
GUIWaiter.h \
Semaphore.h
FORMS += RestaurantSetup.ui
LIBS +=
Full Compiler Output:
g++ -c -pipe -g -gdwarf-2 -arch i386 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -
I/usr/local/Qt4.6/mkspecs/macx-g++ -I. -
I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -
I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -
I/usr/include -I. -I. -F/Library/Frameworks -o main.o main.cpp
In file included from RestaurantGUI.h:10,
from main.cpp:2:
Semaphore.h:14: error: 'sem_t' does not name a type
make: *** [main.o] Error 1
make: Leaving directory `/Users/thauburger/Desktop/RestaurantSimulation'
Exited with code 2.
Error while building project RestaurantSimulation
When executing build step 'Make'
© Stack Overflow or respective owner