Click to See Complete Forum and Search --> : C++ programming


jetblackz
09-18-2002, 01:15 AM
I'm a super newbie to it. Could somebody give me a pointer? Just did hello world. It runs fine.

How do you add a dir after -Idir properly?
Is there a way to test a proggy w/o compiling it? :) I know it's not BASIC.
Any good Websites for Linux programming?
Lastly, is it possible to convert a script to C++ with minimal efforts? If not, how to output a command line in C++?

Thanks much.

l01yuk
09-18-2002, 03:02 AM
How do you add a dir after -Idir properly?
I assume you mean when doing

gcc -Idir

how do you add another dir? Just do another -Idir.


Is there a way to test a proggy w/o compiling it? No point, they would only give you the same errors.

If not, how to output a command line in C++? ???

I suggest you get a book like C++ in 21 days or C++ from the ground up and go through it.

dogn00dles
09-18-2002, 10:21 PM
A command line... i dunno what you're talking about. You could include <stdlib.h> and use the system function to run commands, though. Or maybe you're talking about shellcode used in exploits. I don't know assembly...

jetblackz
09-19-2002, 12:41 AM
Thanks. Yeah the 24 hours book is on my desk. I could be wrong but gcc is for C not C++ proggies. g++ is the for latter and what I'm coding.

What I mean is where to put the path.

gcc -Idir /path

Correct?

Please. The book is Windows-biased. Actually no Linux instructions at all. That maybe what's stopping many budding programmers. I'm one of them. I have no prob writing code, etc. The prob is how to compile it properly, setting up paths, env, etc.

Is cygwin the only option for Windows that offers gcc? Any other packages beside DJGPP, Borland C++ & MSVC++? I would love to do pure C++ coding on Wintel platform.

truls
09-19-2002, 02:37 AM
If you want to include header files located in "/usr/include/myincludes" you would write:
gcc -o file file.c -I/usr/include/myincludes
The include path goes directly after the -I.
Same goes for library paths:
gcc -o file file.c -L/usr/include/mylibraries -lname
In addition you must add the library with the -l (small L) and the name of the library minus the "lib" part of the filename.

So, as an example, let's say you have the library mylib.so, which is located in "/usr/include/mylibraries/mylib.so", which has a header file "/usr/include/myincludes/mylib.h". Your program myprog.c uses this library and includes the mylib.h file, and would be compiled as:
gcc -o myprog myprog.c -I/usr/include/myincludes -L/usr/include/mylibraries -lmy

(I'm on a windows machine now, so there could be some flaws to the above, anyone on a *nix machine please correct).

bwkaz
09-19-2002, 09:28 AM
Most of that's right, except for the library part. If you specify -lmy on the command line, gcc will look for libmy.so, not mylib.so (the "lib" goes before). If you called it mylib.so, you have to explicitly link it in; however, I don't remember how to do that.

jetblackz
09-20-2002, 12:51 PM
Thanks very much everyone!

I'm going in the right direction. Is there such thing as C++ addict? :D

l01yuk
09-20-2002, 08:16 PM
Check out the http://www.faqs.org comp.lang.c++ FAQ. Very good info.

dogn00dles
09-22-2002, 07:09 PM
Originally posted by jetblackz
I could be wrong but gcc is for C not C++ proggies. g++ is the for latter and what I'm coding.

G++ is just a link to GCC with different parameters.

jetblackz
09-23-2002, 12:44 PM
In case anyone wants a lightweight Win32 code editor and C++ compiler, I love these:

http://www.code-genie.com/

http://www.mingw.org/

That's all you need to do single-file C++ coding on Windows.

For Linux, you don't need to download anything, vi & c++ will do.

nuvan
09-25-2002, 01:50 AM
i've heard vi (or at least vim) can do syntax highliting. is this true?

binaryDigit
09-25-2002, 11:09 AM
yes it's true.
http://www.linuxnewbie.org/nhf/Tools/Customizing_vim.html

JockVSJock
09-28-2002, 03:12 PM
Is there a way to test a proggy w/o compiling it? I know it's not BASIC.


Although I haven't used this yet, but GDB appears to be a good debugger, and my programming guru friends really like it, if you are using GCC (with VIM, why would you use anything else?).

http://sources.redhat.com/gdb/

I believe there are MAN pages for GDB as well, but haven't had the time to read them yet.

Check it out and let us know what the results are.

-Chris

bwkaz
09-28-2002, 05:01 PM
You still have to compile to use gdb....

And you have to pass the -g option to either g++ or gcc to get the debugging info in the executable.

Big_daddy
10-01-2002, 08:36 AM
Could somebody give me a pointer?

*ptr

nuvan
10-04-2002, 03:13 AM
Originally posted by Big_daddy


*ptr


void **ptrptr;
*ptrptr = &ptr;
is that code legal?

bwkaz
10-04-2002, 02:57 PM
Only if ptr isn't a pointer, and if ptrptr is initialized to point somewhere before the indirection through it (neither of which are likely).

It should be something more like this, I think:

int x = 0;
int *ptr = &x;
void **ptrptr; /* or int ** would work, but I assume you have a valid reason for using void **... */

ptrptr = &ptr;

Haunted
10-07-2002, 11:21 PM
Hi people. I am a reall newbie to the Linux, but I have study some c++ on Windows using Code Warrior IDE. I tryed to compile the following Hello World program with gcc, but it didn't work, though I know that syntax is correct. I would really appreshiate of somebody would help me. Here is the program.

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!\n\n";
return 0;
}


Please don't be too harsh on me :) Thankyou.

bwkaz
10-08-2002, 09:08 AM
gcc doesn't compile C++ programs (well, you can make it, but it's painful ;) ). For that, use g++ instead.

Edit: and if that doesn't work, post the error you're getting.

Haunted
10-08-2002, 06:12 PM
bwkaz , thankyou! It's working now :)

nuvan
10-09-2002, 10:37 PM
Originally posted by Haunted
Hi people. I am a reall newbie to the Linux, but I have study some c++ on Windows using Code Warrior IDE. I tryed to compile the following Hello World program with gcc, but it didn't work, though I know that syntax is correct. I would really appreshiate of somebody would help me. Here is the program.

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!\n\n";
return 0;
}


Please don't be too harsh on me :) Thankyou.

just so you know, IIRC, the convention in C++ is to use endl in place of \n. So the code would now look like
cout<< "Hello World!" << endl;
of course, the old \n still works, but I just thought you'd like to know.