Subj : Problems with 'undeclared' variables during compilation To : comp.programming.threads From : mckrs Date : Mon Apr 11 2005 03:11 pm Hello all, I am attempting to get a multi-threaded C++ program off the ground in a Sun Solarix environment. In this particular situation, I am required to use namespaces. The problem is that I get this error when I attempt to compile using: 'g++ -lpthreads -o ERROR MESSAGE: sourcefile.cpp:218: error: `fOut' undeclared (first use this function) I can't seem to figure out why the compiler cannot find the 'fOut' file handle. Any help is truly appreciated! - Garbunkel Here is a sample of the code: // For I/O capabilities #include #include // For file handling capabilities & random character generation #include #include #include #include #include #include bool writelock; int readers, readersqueued, writersqueued; pthread_cond_t active_wr_cond; pthread_cond_t active_rd_cond; pthread_mutex_t mutex; char *thetime; int numofreadloops; int numofwriteloops; // *****************************/ // Constant exit handlers int INCORRECT_EXECUTION_SYNTAX = -1; int PTHREAD_MUTEX_INIT_ERROR = -2; int PTHREAD_COND_INIT_ERROR = -3; int PTHREAD_RD_CREATE_ERROR = -4; int PTHREAD_WR_CREATE_ERROR = -5; int PTHREAD_WR_COND_SIGNAL_ERROR = -6; int PTHREAD_WR_COND_WAIT_ERROR = -7; int PTHREAD_RD_COND_SIGNAL_ERROR = -8; int PTHREAD_RD_COND_WAIT_ERROR = -9; int PTHREAD_JOIN_ERROR = -10; int OUTPUT_FILE_CREATE_ERROR = -11; // *****************************/ // Function declarations void* monitor_rd(void *arg); void* monitor_wr(void *arg); void beginreader(void *param); void beginwriter(void *param); void endreader(); void endwriter(); void updateDB(); char* GetDB(); bool randnumisodd(); int main (int argc, char* argv[]) { using namespace std; char outfilename[255]; int numofreaders, numofwriters, numofops; int jobind = 0; if (argc < 6) { printf("\nUsage:mon<# of rdrs><# of wrtrs><# of rdr loops><# of wrtr loops>\n"); exit (INCORRECT_EXECUTION_SYNTAX); } numofreaders = atoi(argv[1]); /* r */ numofwriters = atoi(argv[2]); /* w */ numofreadloops = atoi(argv[3]); /* R */ numofwriteloops = atoi(argv[4]); /* W */ strcpy (outfilename, argv[5]); /* Output file name */ ifstream fIn("test.dat",ios::in); numofops = numofreaders + numofwriters; /* Set initial DB value in main thread */ updateDB(); // Attempt opening output file ofstream fOut(outfilename,ios::out); // This is the problem line .