Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:27:45+00:00 2026-05-15T02:27:45+00:00

I’m working on a simulation in Qt (C++), and would like to make use

  • 0

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'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:27:46+00:00Added an answer on May 15, 2026 at 2:27 am

    I was able to compile and link your semaphore class using qmake without any unexpected steps (including linking in the rt or pthread libraries). I created the following main:

    #include "Semaphore.h"
    
    int main(int argc, char* argv[])
    {
            Semaphore sem;
            return 0;
    }
    

    And then I generated the following project file using qmake -project:

    ######################################################################
    # Automatically generated by qmake (2.01a) Mon May 24 12:50:02 2010
    ######################################################################
    
    TEMPLATE = app
    TARGET = 
    DEPENDPATH += .
    INCLUDEPATH += .
    
    # Input
    HEADERS += Semaphore.h
    SOURCES += main.cpp Semaphore.cpp
    

    Whatever error you’re seeing is caused by something other than your Semaphore class. I’d recommend taking a good look at your RestaurantGUI.h file. You may need to take a look at the preprocessed output (gcc’s -E flag) in order to see what’s really happening.

    NOTE: I’d recommend renaming your semaphore files to something that will work on case-insensitive filesystems, such as Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.