LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2005, 07:59 AM   #1
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
Making/Compiling C++ programs via CLI


Hi,

I have tried GUI programs like the Anjuta IDE but it was so confusing that I couldn´t even start typing in the main.cpp file! So, I want to do it the ¨old-fashioned¨ way. If I type a bunch of C++ code into gedit, then save the file as main.cpp and put that into a random folder, do I compile it by going into terminal, cd-ing to the directory, and typing in ¨gcc main.cpp¨? What file will that then make, and how do I run it?

Sorry, but I´ve only ever coded C++ on Windows, so I´m used to used the Borland C++ compiler and to it producing .exe files, etc...As I´m trying to use Linux more than Windows, and eventually get rid of it, please can you help me compile C++ files? Thanks,

J_K9
 
Old 07-09-2005, 08:11 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Re: Making/Compiling C++ programs via CLI

Quote:
Originally posted by J_K9
Hi,

I have tried GUI programs like the Anjuta IDE but it was so confusing that I couldn´t even start typing in the main.cpp file! So, I want to do it the ¨old-fashioned¨ way. If I type a bunch of C++ code into gedit, then save the file as main.cpp and put that into a random folder, do I compile it by going into terminal, cd-ing to the directory, and typing in ¨gcc main.cpp¨? What file will that then make, and how do I run it?
You need to do "g++ main.cpp" without the quotes. The file produced will be called a.out, so you need to type "./a.out" to run it, again without the quotes. If you want the executable to be called something else, use "g++ main.cpp -o main". Here the executable will simply be called main.

HTH .
 
Old 07-09-2005, 12:35 PM   #3
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Original Poster
Rep: Reputation: 30
Hi,

Thank you, but an error occurred when I tried ¨g++ main.cpp¨. Here is the output:
Code:
jk9@ubuntu:~/Desktop$ g++ main.cpp
main.cpp: In function `int main()':
main.cpp:5: error: stray '\302' in program
main.cpp:5: error: stray '\250' in program
main.cpp:5: error: `Hello' undeclared (first use this function)
main.cpp:5: error: (Each undeclared identifier is reported only once for each
   function it appears in.)
main.cpp:5: error: parse error before `!' token
main.cpp:5: error: stray '\' in program
main.cpp:5: error: stray '\302' in program
main.cpp:5: error: stray '\250' in program
jk9@ubuntu:~/Desktop$
This is really weird because I´m sure this basic c++ file is correct...Just to check, here is the code:
Code:
#include <iostream>

int main()
{
	std::cout << ¨Hello world!\n¨;
	return 0;
}
So, instead of ¨#include <iostream>¨. When I tried <iostream.h> the compiler told me it was outdated and also produced the same errors...please can you tell me what is wrong? Thanks,

---------------------------------------------------
edit: Now I know what was wrong. Since yesterday, my keyboard has been acting extremely strangely...whenever I press the ¨v¨ key, my home folder pops up in Nautilus, and the actual letter isn´t typed. So far, the only work-around I have managed to find is to go into terminal, type ¨ls /¨ and copy the v from var. Then I paste that wherever I want a v.

Another problem I have, which is the one related to this, are my speech marks and inverted commas. Look at your speech marks " and now look at mine ¨. Don´t you see that mine are different? I have to press the ¨ key twice for it to appear, and the ´ key twice for that to appear. Can someone please tell me what is wrong, and how I could fix this? What I did was I copied your " and replaced mine (¨) with them, and the program worked! Thanks for helping me out with g++, but could someone also please help me with this problem? Thank you ery much,

J_K9

Last edited by J_K9; 07-09-2005 at 12:44 PM.
 
Old 07-09-2005, 12:55 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You need to use the double quotes and not two single quotes. That's the only problem, because as far as I can see, the rest of the code is ok. Where they are on your keyboard depends on the layout. On my keyboard (GB), they're above the number 2. I think on a US keyboard, they're on the same key as @, but I'm not sure.

Edit: there's a setting to choose your keyboard layout in your config file for X11 (mine's called xorg.conf and is in /etc/X11. Sometimes the file is called XF86Config or similar). Do a "locate xorg.conf" in a terminal (without the quotes), or try locate with XF86Config to find it. You'll need to become root to edit it and then you'll need to restart your X server for changes to take effect.

Last edited by Nylex; 07-09-2005 at 01:00 PM.
 
Old 07-09-2005, 01:06 PM   #5
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Original Poster
Rep: Reputation: 30
I was using double-quotes: I have an English laptop, but I wasn´t sure which keyboard to select in my Ubuntu preferences.

What I meant by ¨I have to press the key twice¨ is that if I press the key for ¨ (Shift + 2) nothing appears, unless I press it twice in a row with the Shift key still down. And when it appears, it looks like this: ¨, instead of your normal speech marks. Likewise, with the ´ key, I have to press it twice for the ´ to come out: if not, and I´m typing the word _it´s_ (for example), I´ll end up with _itś_. This is really weird: shall I try changing keyboard settings? It´s just that I'm very confused because my current setting is "United Kingdom -> International (with dead keys)".

edit: I have just changed to an American setting, and even though the keys are not in the right places, at least I get proper " and ' and only ha to press the keys once. The "v" problem still remains....it's not in "Keyboard Shortcuts". I don't know what to do! Please help me!

J_K9
 
Old 07-09-2005, 01:15 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
You were typing umlauts instead of double quotes ...

you can use xev to find out what your keys are mapped to.

Last edited by jlliagre; 07-09-2005 at 01:18 PM.
 
Old 07-09-2005, 01:20 PM   #7
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Original Poster
Rep: Reputation: 30
Oh...right...now that I have switch to the American keyboard layout (which isn't my laptop's keyboard layout, but anyway...) it works, and I'm no longer getting the umlauts thing but speech marks/double quotes. Do you know how I can stop the weird "v" thing? At the moment, as I said in my last post, I hae to carry on copy-and-pasting each "v" I type, and at the moment I have 6 open windows from when I've accidentally pressed "v" instead of paste (Ctrl + v). Please help me - this is very annoying, but at least the umlauts problem has gone, and I don't mind using a keyboard layout which isn't the same as mine as long as it works...

edit: This is the output of typing the letter I can't type into xe(letter)
Code:
FocusOut event, serial 26, synthetic NO, window 0x3400001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 26, synthetic NO, window 0x3400001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 26, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
Any ideas?

J_K9

P.S Sorry I ha(letter)e to go away for the weekend but I will reply as soon as I get back!

Last edited by J_K9; 07-09-2005 at 01:33 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting CLI programs in aterm when logging in ethics Linux - General 0 11-29-2005 07:34 PM
loading CLI programs in X at startup edM Slackware 3 10-20-2005 10:29 PM
making your own programs for linux linuxmandrake Linux - Software 6 06-09-2005 08:30 AM
Making programs lock to one desktop linux-nerd Linux - Software 1 09-16-2004 04:42 PM
Making some programs default and another questions... Mega Man X Linux - General 4 07-19-2003 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration