Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows c++ code i want to port on Linux

MyClass.h

C++
class MyClass
{
private:
	#ifdef WIN32
		CRITICAL_SECTION _mutex_obj_;
	#else
		pthread_mutex_t _mutex_obj_;
		pthread_mutexattr_t _mutex_obj__attr_;
	#endif
protected:

public:
	MyClass();
	virtual ~MyClass();

};


MyClass.cpp

C++
MyClass::MyClass()
{
	#ifdef WIN32
		InitializeCriticalSection(&_mutex_obj_);
	#else
		pthread_mutexattr_init(&_mutex_obj__attr_);
		pthread_mutex_init(&_mutex_obj_, &_mutex_obj__attr_);
		pthread_mutexattr_destroy(&_mutex_obj__attr_);
	#endif

}

MyClass::~MyClass()
{

}


when compiled i get this error Member declaration not found

Thanks in advanced
Posted
Updated 21-Sep-14 22:12pm
v2
Comments
Sergey Alexandrovich Kryukov 22-Sep-14 3:52am    
This message looks weird. In what line? And what's the point to have constructor and destructor doing nothing? (If this is just for showing a problem, it's perfectly fine.)
Are you saying you have the code compiling on Windows, but failing with GCC?
—SA
[no name] 22-Sep-14 4:05am    
i did not add the rest of the code since the error only appear on MyClass::MyClass() , and yes the code run on windows but failing with GCC.
Sergey Alexandrovich Kryukov 22-Sep-14 4:08am    
It would be fine, but it's hard to imagine that such simple code can cause such problem. So, are you sure that's it? You did not answer my question...
—SA
[no name] 22-Sep-14 4:14am    
i updated the code.
Richard MacCutchan 22-Sep-14 4:51am    
Which line does the error occur on, and what is the exact text of the message?

1 solution

This code:
C++
#ifndef WIN32
#include <pthread.h>
#endif

class MyClass
{
private:
  #ifdef WIN32
    CRITICAL_SECTION _mutex_obj_;
  #else
    pthread_mutex_t _mutex_obj_;
    pthread_mutexattr_t _mutex_obj__attr_;
  #endif
protected:

public:
  MyClass();
  virtual ~MyClass();

};

MyClass::MyClass()
{
  #ifdef WIN32
    InitializeCriticalSection(&_mutex_obj_);
  #else
    pthread_mutexattr_init(&_mutex_obj__attr_);
    pthread_mutex_init(&_mutex_obj_, &_mutex_obj__attr_);
    pthread_mutexattr_destroy(&_mutex_obj__attr_);
  #endif

}

MyClass::~MyClass()
{

}

int main()
{
  MyClass mc;
}


compiles (and runs) fine on my Ubuntu box (don't forget to link with pthread library).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Sep-14 10:34am    
5ed. OP still did not show us where was the error, so I suspected mismatch between reported error and the code shown, misrepresented problem observation. The error was about the lack of declaration, not definition with reported not found symbol.
—SA
CPallini 22-Sep-14 11:38am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900