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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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...
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,
/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 188.8.131.52 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-
g++ assumes preprocessed (.i) files are C++ and assumes C++ style
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.
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.