LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 09-22-2003, 11:29 PM   #1
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Rep: Reputation: 30
How to compile a executable dos file by g++?


For example,
Code:
#include<iostream>
using namespace std;

int main ()
{
   cout<<"hi"<<endl;
}
how to compile the code above to a executable dod file, such as *.exe, *.bat by g++ in linux?
Thank you.
 
Old 09-22-2003, 11:32 PM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
linux doesn't need those type of file extensions, but if you want, use:

g++ -o hi.exe hi.cpp

edit: if you're talking about compiling that in linux and having it run in windows/dos, it won't to my knowledge. you have to compile the source code in windows/dos so it will run in windows/dos.

Last edited by megaspaz; 09-22-2003 at 11:39 PM.
 
Old 09-22-2003, 11:46 PM   #3
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
Thank you.
Yes, I want use the compiled file in dos/windows.

However, some compiler, such as Kylix can achieve this.
So I guess perhaps g++ also can achieve this.

Edit:
What about makefile's suffix rule?
I'll give it a go.



Last edited by Xiangbuilder; 09-23-2003 at 12:01 AM.
 
Old 09-23-2003, 12:17 AM   #4
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
let's be clear here. i'm under the impression kylix can not do what you want. the target computer has to have kylix installed for you to be able to do it. either way, it's still not a straight compile and run. i could be mistaken about this, but i'm pretty sure with kylix you still have to make sure certain things are in order on the target machine. i am pretty sure that compiling source code using g++ in linux will not create a binary that will run in windows/dos.
 
Old 09-23-2003, 12:48 AM   #5
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
Thank you for your answer.
 
Old 09-23-2003, 05:16 AM   #6
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 30
The same is also the case with the compilers over all the OS. If you want to have to create a program that runs irrespective of platform, go for interpreted languages like perl, or better yet, go for JAVA.
 
Old 09-23-2003, 06:22 AM   #7
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
There is a cross-compiler for MinGW:
http://www.mingw.org/mingwfaq.shtml#faq-cross
 
Old 09-23-2003, 08:56 AM   #8
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
Thank you.
I'll try it.
 
  


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
how do I lauch a file by its executable cjae Suse/Novell 1 07-12-2005 11:51 AM
Linux Executable File Help (created from a .c file) MattG1981 Linux - Newbie 7 06-06-2004 04:54 PM
how to install an executable file props666999 Slackware 4 05-29-2004 03:50 PM
kernel 2.6.3 compile ends in grub error 13: unsupported executable format(?) browny_amiga Linux - General 4 03-06-2004 02:33 PM
VB executable file decompiler XillusionsX Programming 3 10-29-2002 01:11 AM


All times are GMT -5. The time now is 07:31 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration