ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 am learning C++. I used Windows Vista and Visual C++ Express edition.
But I read in some article that linux is better to program in. So I got Ubuntu installed and an eclipse IDE for C++. But it doesn't run anything.
When I tried to run this I got an error saying cannot find "iostream" :
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
return 0;
}
What would I have to do to compile and run it?
My vista is on another partition and when I access it, while in Ubuntu, and try to run the .exe applicationss I created with VC++ nothing works?
...
My vista is on another partition and when I access it, while in Ubuntu, and try to run the .exe applicationss I created with VC++ nothing works?
Any help is appreciated.
It's probably too early for you to learn programming if you are blindly trying to run an application compiled for one OS to run under another OS.
I suggest to first learn what in general is compilation, linking, loading, executing, how binary file formats differ, what are file permissions under Windows and under UNIX, what in the end is executed, what are basic OS functions WRT programs, etc.
It's probably too early for you to learn programming if you are blindly trying to run an application compiled for one OS to run under another OS.
But he's not trying to run an application previously compiled for any OS at all. He's trying to compile it in Linux, as he said:
Quote:
What would I have to do to compile and run it?
Edit: Actually, Sergei, you're right. He was trying to blindly run those exe's. swish, don't try to run those exe's. But you're on the right track when you realize that you have to "compile and run it". That will involve making a new compiled executable for Linux; your Microsoft exe's are no good here.
swish, I've never used an IDE under Linux; I'm a command line kinda guy. But run this as a shell script, and it should compile and run your C++ program. If it doesn't compile, then it's a good bet that your compiler isn't installed properly. But it probably will compile and run:
But he's not trying to run an application previously compiled for any OS at all. He's trying to compile it in Linux, as he said:
Edit: Actually, Sergei, you're right. He was trying to blindly run those exe's. swish, don't try to run those exe's. But you're on the right track when you realize that you have to "compile and run it". That will involve making a new compiled executable for Linux; your Microsoft exe's are no good here.
swish, I've never used an IDE under Linux; I'm a command line kinda guy. But run this as a shell script, and it should compile and run your C++ program. If it doesn't compile, then it's a good bet that your compiler isn't installed properly. But it probably will compile and run:
He might not have the right path set for the includes also. If cpp runs, one would expect the basic C++ includes to be present. Of course, we don't know that he actually tried to compile with cpp; he might have used gcc.
The command "locate iostream" should shed some light on the subject.
IMHO, if you are just starting to learn to program in C or C++, you shouldn't work in an IDE. You need to learn the g++ command and options, and creating make files on your own. The IDE would do this for you and do it so generally, with so many options, that it will be impossible to fathom for a beginner. You need to learn to swim before deep sea scuba diving.
It is ironic that making things easier, adds a lot of complexity.
I think I figured out what the problem is.
Eclipse said it needed java to run.
I went to the java site and all of those were for other distros(redhat), I have Ubuntu. So I used Synaptic to install another java runtime. When I started eclipse it gave me an error something like this, "Eclipse *version blah* has never been tested on this java platform.Continue?" I didn't take that seriously I guess and thats probably why it won't compile right.
Quote: Sergei Steshenko:
Quote:
It's probably too early for you to learn programming if you are blindly trying to run an application compiled for one OS to run under another OS.
The only .exe I tried to run were like dead simple console apps. Ex. "Hello World".
But I realized that I have to recompile apps to run it on linux.
So after some research...this is my notion:
.exe files compiled in Win32 architecture won't run in linux? But if you get the source code and recompile it on linux it will run? Am I right?
Also, I really want to use command line(helps me think easier without all the unnecessary gui). But if I used command line what about error checking? I don't want it to run and just crash.
Can someone give me a website that explains using command line to compile and run, can't be too advanced(i am newbee)? Also, a website on what Sergie was talking about:
Quote:
Originally Posted by Sergie
I suggest to first learn what in general is compilation, linking, loading, executing, how binary file formats differ, what are file permissions under Windows and under UNIX, what in the end is executed, what are basic OS functions WRT programs, etc.
...
Also, I really want to use command line(helps me think easier without all the unnecessary gui). But if I used command line what about error checking? I don't want it to run and just crash.
...
What is your definition of error checking ?
Why do you think IDE is different from command line WRT error checking ?
How are you going to differentiate between IDE bugs and your program bugs ?
How are you going to differentiate between whatever library your program uses bugs and your bugs ?
...
Can someone give me a website that explains using command line to compile and run, can't be too advanced(i am newbee)? Also, a website on what Sergie was talking about:
.exe files compiled in Win32 architecture won't run in linux? But if you get the source code and recompile it on linux it will run? Am I right?
Yes, and the bash script I posted earlier demonstrates how this can work.
Your source code doesn't do all the work itself. It depends on two other entities to help it:
One entity is libraries. These contain code that you could just as well have written yourself and included as part of your code, but this saves you the trouble. They include math routines (sine, cosine, and so on), data formatting routines (for converting native floating point numbers into strings of characters which are printable) and many other things.
Another entity is the operating system. This includes code that you couldn't simply incorporate into your own code, because the operating system won't normally allow you to do these things yourself. Things like doing actual I/O with ready-to-go arrays of bytes, getting your process ID, starting a child process, and exiting.
The way your compiled code requests the operating system to do things covered by that second item varies wildly from operating system to operating system. There are other reasons why your compiled Windows code won't run under Linux, but that reason is one of the most conspicuous.
Quote:
Visual Studio would shoot out a message saying "cut" undeclared identifier
The Linux compiler will do the same thing, and will not continue to produce a linked object file. These are known around here as "compilation errors".
Quote:
But I am talking about large scale programs.
If you have 500,000 compilation errors in your code, you'll see them all fly past you on the screen. When I'm confronted with that, I do the compilation command thus:
Code:
clear; g++ your options and stuff here 2>&1 | less
I do the "clear" because if you've been compiling and compiling and you get the number of error message lines down to, say, 10 or so, you won't have to squint at the screen to separate the most recent compilation errors from the ones in the previous compile.
In the "options and stuff", definitely include the -Wall option that Sergei recommended. Upper case W.
When you talk about "large scale programs", maybe you're not talking about handling zillions of error messages. Maybe you're talking about compiling subzillions of source files. The classic (for decades and decades) program for taking care of that is "make". Do this at the command line:
Code:
man make
Using make is not a black art and not rocket science, but it can present gotchas for the unwary, and there are many wrinkles to it. Don't rely on just the man page. scroogle the following search terms:
Code:
make tutorial
and knock yourself out.
I avoid make. My projects don't take that long to compile from scratch, so I just construct a bash script to do it all each time.
Oh. And.
Speaking of errors: I assume you're doing error checking on all your function calls, right? Full details for such error checking are found in the man pages. You know about man pages, yes? If you don't, then do this at the command line:
Code:
man man # definitely do this one
man fork # here's another example
This kind of error handling should be no different from what you do in Windows, though I have no experience in Windows.
Now as to the link that Sergei posted, the space in the original link showed itself as a larger problem, because the linuxquestions software left out the space and everything after it as part of the link. So if you use his advice, you'll have to copy and paste not just the link as shown in his post, but also everything up to and including the "htm". As an alternative, click on this link, lovingly repaired by hand.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.