473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Dining Philosophers / C++/ Linux question

I am attempting to compile this in Fedora:

http://www.math-cs.gordon.edu/courses/cs322/projects/p2/dp/c++/philosopher.cc

I've used all of the source files and the makefile provided yet I am getting the errors:

undefined reference to 'msecond'
undefined reference to 'random_int'

Our Linux teacher was very sketchy on how to actually write makefiles / compile programs in general (he basically told us to go read the Man Pages and use Google) so I've been using these lines to compile, make, and finally run the program:

Expand|Select|Wrap|Line Numbers
  1. g++ -lpthread dining_philosophers.cc
  2. make
  3. ./dining_philosophers
If I can get this to compile and run I can actually see what the Dining Philosophers problem is supposed to look like, and then be able to start my own program.
Apr 7 '08 #1
4 5011
gpraghuram
1,275 Expert 1GB
msecond.h is available in the path and r u specifying the path properly?
Also in the file compile option is being specified.

Raghuram
Apr 8 '08 #2
Yeah I wasn't compiling right, I wasn't linking the two .h files with the .cpp/cc file. This line worked though:

Expand|Select|Wrap|Line Numbers
  1. g++ dining_philosophers.cc -lpthread msecond.o random_int.o
Thanks for the tip.
Apr 8 '08 #3
Alright I have another question regarding this. I modified the program so it works for any number of Philosophers, however the downside is that number has to be a predefined constant. I'm using this Semaphore class:

Expand|Select|Wrap|Line Numbers
  1. class Semaphore
  2. {
  3. private:
  4.      sem_t semaphore
  5. public:
  6.      Semaphore(int value = 1) {(void) sem_init(&semaphore,0,value);};
  7.    ~Semaphore(void)   {(void) sem_destroy(&semaphore);};
  8.      void wait(void)    {(void)sem_wait(&semaphore);};
  9.      void signal(void) {(void)sem_post(&semaphore);};
  10. };
This will take an array declaration like:

Expand|Select|Wrap|Line Numbers
  1. Semaphore a[index];
Does anyone know of a way to make a Semaphore based class take a vector structure? I need to use a Vector or some other structure that takes a variable input, so I can scale the number of Philosophers needed.

Or can I just create a generic Semaphore to block access while I do work on a normal vector? Such as:

Expand|Select|Wrap|Line Numbers
  1. s.wait();
  2. //-- Vector operations here
  3. s.signal();
Apr 8 '08 #4
The edit button disappeared >_<. Anyway, I figured the above out, turns out I didn't have to use a vector afterall.

Anyway, I'm trying to use a makefile to put this thing all together, yet it's throwing errors at me. Anyone know what's wrong with this:

Expand|Select|Wrap|Line Numbers
  1. CC = g++ 
  2. CFLAGS = -Wall -Ansi 
  3. OBJECTS = dining_philosophers.o msecond.o random_int.o
  4. project2: $(OBJECTS)
  5.     $(CC)$(CFLAGS)$(OBJECTS) -o dining_philosophers msecond random_int
  6. dining_philosophers.o: dining_philosophers.cpp
  7.     $(CC)$(CFLAGS)$(OBJECTS) -lpthread dining_philosophers.cpp
  8. msecond.o: msecond.c msecond.h
  9. random_int.o: random_int.c random_int.h
  10.  
  11. #clean
  12. clean:
  13.     /bin/rm -f dining_philosophers*.o 
  14.  
The terminal looks like this (with errors):

Expand|Select|Wrap|Line Numbers
  1. g++ -Wall -Ansi dining_philosophers.o msecond.o random_int.o -lpthread dining_philosophers.cpp
  2. g++: dining_philosophers.o: No such file or directory
  3. g++: msecond.o: No such file or directory
  4. g++: random_int.o: No such file or directory
  5. <command line>:1:4: error: missing '(' after predicate
  6. make: *** [dining_philosophers.o] Error 1
I'm really new with makefiles, so do I have to do something else to make it generate the .o files?
Apr 9 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Ranger West | last post by:
Hello there, Are there any out-of-the box handhelds that run Linux/Apache/MYSQL and PHP? Does Redhat, Suse, or Gentoo support any handhelds? I know the Zaurus comes close, but I've heard...
4
by: Jhuola Hoptire | last post by:
Just installed J2RE 1.4.2 on a Linux server. I am very knew to the POSIX world. I couldn't dig-up much in the docs or via google about the following: 1 - Is there a standard way to make sure...
34
by: Maboroshi | last post by:
Hello My question has to do with python and linux - I was interested in finding out what it would take to reimplement the Linux Kernel in python basically just taking the source code from linux...
17
by: gnu | last post by:
You can compile anything you want. Redistribute anything you want. You can name the OS distribution your name burn CDs with it and make a donation to 100 schools. You can make a distribution boot...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
4
by: Joćo Pires | last post by:
I have a program write in VB and I need to convert the code to C for Linux. Well, I began to do that but I have some problems ... - How can I write te code in C to comunicate with the serial...
17
by: Jim Strickland | last post by:
We currently are running a data intensive web service on a Mac using 4D. The developers of our site are looking at converting this web service to PostgreSQL. We will have a backup of our three...
191
by: Xah Lee | last post by:
Software Needs Philosophers by Steve Yegge, 2006-04-15. Software needs philosophers. This thought has been nagging at me for a year now, and recently it's been growing like a tumor. One...
7
by: raghu | last post by:
Hello How to create a task in C on linux operating system? Awaiting for the reply Thanking you in advance -Raghu
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.