Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm taking an operating systems class, and I've been our of school for a couple years now. I'm having to do a project in C on a UNIX system, and I really don't remember jack about programming in C. To compound the issue, I've never programmed C on a UNIX machine. I'm having some really, really basic issues here and I'm sure that I'm just making a pathetically stupid mistake...
$ gcc test.c
In file included from test.c:1:
/usr/include/c++/3.2.2/backward/iostream.h:32:20: iostream: No such file or directory
/usr/include/c++/3.2.2/backward/iostream.h:34: parse error before "std"
test.c: In function `main':
test.c:5: `cout' undeclared (first use in this function)
test.c:5: (Each undeclared identifier is reported only once
test.c:5: for each function it appears in.)
test.c:4: warning: return type of `main' is not `int'
What's also confusing me is that there are two copies of iostream.h on my system and they give me different errors when included. Here are the directories they are located in...
And finally, I have to turn in my project as a "makefile." I've never messed with make except to compile things I'm installing. Can anyone point me to some info on make?
Okay, here's what I've done per your suggestions so far... I changed the filename to test.cpp. I changed the include to just iostream.h. This didn't work before, but since I changed the filename of test.c to test.cpp, it seemed to find the correct file (/us/include/c++/3.2.2/backward/iostream.h). I also changed the return of main to an int and added a return(1); line at the end of the main function. Now I get the following errors...
$ gcc test.cpp
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from test.cpp:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccFNt7WS.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/tmp/ccFNt7WS.o(.text+0x1e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccFNt7WS.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccFNt7WS.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccFNt7WS.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
gcc assumes preprocessed (.i) files are C and assumes C style link-
ing.
g++ assumes preprocessed (.i) files are C++ and assumes C++ style
linking.
They are mostly the same program it just depends on how they make assumption. Usually when I have just one source file I type `make test` or whatever and make will use the right one. Sometimes I get away with using gcc for c++ programs... but yeah g++ is the correct program to call.
Note: Typing `make test` will automatically make sure the output is test... instead of a.out. I don't know how big this project, you are going to be doing, will be but you might want to look into how to use make. Also, if you really want to take the easy road... use kdevelop -- It is the only program I use from the KDE project but it is very nice.
try `info make.info` It will tell you all about it.
A Makefile is just a set definition telling make how to build your program. It is really nice, especially since it can be setup to only recompile the stuff that has changed and you will only have to type one thing to rebuild you program. Imagine you have 10 cpp files.
My project is supposed to be using system calls (i.e. fork(), exec(), etc.). How do I use these in C++? Is there a header file I need to be including? I get errors when I try to use them in a program.
That should do it. I believe those two include files should have everything you need. I know they define fork and exec -- at the very least. I believe they have the rest of the system calls.
Okay, here are a few more questions for you programming wizards... I have to write a program that will create a child process with the fork() command. I've successfully done that, but here's what I don't know how to do:
1) How do I identify the parent's process id (PPID) in the child process?
2) How do I register which function will be my signal handler?
3) How do I create pipes between the two processes? Can I create them before the fork and then have them be inherited?
4) How can I run a shell command from the C++ program, and how can I get the output of that command to be handled by the C++ program instead of being output to the screen?
Thanks again, guys. I really appreciate the assistance.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.