views:

71

answers:

2

i got a new programing book (multicore programming by cameron hughes, tracey hughes). so far i have not got one of their programs to work their book says that it should work on 99% of computers so im a little confused but at the end of each program in their book they have "compile and link instructions"... do i need to enter that? it looks something like this "C++ -o guess_it guess_it.cc". the code im runnning right now is:

#include <iostream>
#include <windows.h>
#include <string>
#include <spawn.h>
#include <sys/wait.h>

using namespace std;

int main(int argc,char *argv[],char *envp[])
{

 pid_t ChildProcess;
 pid_t ChildProcess2;
 int RetCode1;
 int RetCode2;
 int Value;
 RetCode1 = posix_spawn(&ChildProcess,"find_code",NULL,
                        NULL,argv,envp);
 RetCode2 = posix_spawn(&ChildProcess2,"find_code",NULL,
                        NULL,argv,envp);
 wait(&Value);
 wait(&Value);
 return(0);
 }

im running windows 7(32-bit), AMD athion x2 7550 dual-core proessor, VC++ 2008 Express edition. i get the following error : fatal error C1083: Cannot open include file: 'spawn.h': No such file or directory

anyone know why i can't get my code to run? do i need to download something? because i read the book and did not see anything about downloading anything but i might be wrong. :(

+3  A: 

It looks like that book is using POSIX threading. Visual Studio uses Windows Threading by default, which has a completely different API.

You most likely just need to get a copy of a POSIX Thread library for Windows. That will include spawn.h and the appropriate lib files for you to use.

Reed Copsey
xD k ty i'll try it and see how it gos
blood
uhh i can't find how to download O_o can i have a little help? that link is fine but the download links just take me to a big thing of files and i don't know what to download or how.
blood
thank you, that explains a lot. but i can't get it to work yet so i'll see what i can find with google about that anyway ty again ^^
blood
+1  A: 

Forgive me if I'm misreading your level of experience here, but it sounds as though you are a complete beginner with this language.

The example compilation and link instruction in the book

C++ -o guess_it guess_it.cc

is an example of how to invoke a compiler and linker from the command line. If you're using Visaul C++ then the IDE will automate the compilation and link process for you when you click the "build" button, so you don't need to worry about doing this from the command line.

On to the error you're seeing in VC++:

The compiler is telling you that it can't find the header file spawn.h, which you've told it that your program needs in the line

#include <spawn.h>

As other on this page have mentioned, spawn.h is a file supplied by the POSIX standard libraries and contains functionality for spawning new processes.

Respectfully, it sounds to me from the way you asked your question ("compile and link instructions") as though you don't really understand what you're doing. Before you delve into multi-threading in C++, I recommend taking a step back and find a beginner's book on C++ using Visual Studio, and start from the beginning. I'm afraid you'll make very little progress unless you take the time to learn the fundamentals, and using the compiler is about as fundamental as it gets!

Good luck!

sgreeve
:| im not new to C++ i just have never tryed linking anything..
blood
Again, with all due respect, not sure how those two comments can both be true. You're familiar with the syntax, but have never built a program from more than one object file?
sgreeve
Modern C++ IDEs (esp. Microsoft's with all the "Wizards") can let you write a whole lot of code...GUIs, play music, whatever...and never have to twiddle with linker settings to pull in a third party library. They can even wrap up the error messages into to-do lists so a beginner wouldn't be conscious of whether an error came from the "compiler" or the "linker".
Hostile Fork
@Hostile Fork I don't disagree - but I'm suggesting that not understanding a simple "this file's missing" error is a sign that perhaps he's not yet ready to tackle the joys of multithreaded dev.
sgreeve
I may know more about semiconductors than you do, but I'm not going to tell you not to use your computer until you can do VLSI. :P If the guy had enough motivation to buy a certain book and wants to work through the examples in it...it's possible for him to learn within that context once its established. That's how learning is, there's never a perfect order--even if there were, it might not be any fun if it puts off the part that interests us too long.
Hostile Fork