LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Portable C/C++ exe (http://www.linuxquestions.org/questions/programming-9/portable-c-c-exe-884071/)

golmschenk 06-02-2011 12:13 AM

Portable C/C++ exe
 
I know that C/C++ programs usually need to be compiled specifically for the system they are going to be run on. However, I'm wondering if there's a way to get around this. I plan to make a program that preforms very simple manipulation of an image, but I would like to distribute it to people in the form of an exe. Is there an easy way to make the program run on any system without the user needing any knowledge of how to compile a C/C++ program? Can I easily package the program in a way that it can self compile?

Thanks for putting up with this question. I'm not used to making programs for people on windows or those who I won't expect to use a make file.

dugan 06-02-2011 12:19 AM

No.

This is one reason Java exists.

golmschenk 06-02-2011 12:31 AM

I thought that might be the case. I've never used Java before, but I think I'll give it a try then. It's should end up being a simple program so I guess it's a good place to start anyway. Thanks for the quick reply!

Sergei Steshenko 06-02-2011 04:31 AM

Quote:

Originally Posted by golmschenk (Post 4373776)
I know that C/C++ programs usually need to be compiled specifically for the system they are going to be run on. However, I'm wondering if there's a way to get around this. I plan to make a program that preforms very simple manipulation of an image, but I would like to distribute it to people in the form of an exe. Is there an easy way to make the program run on any system without the user needing any knowledge of how to compile a C/C++ program? Can I easily package the program in a way that it can self compile?

Thanks for putting up with this question. I'm not used to making programs for people on windows or those who I won't expect to use a make file.

For a program to self-compile one needs development tools to be installed on the target machine. And all the libraries needed by your program.

SigTerm 06-02-2011 06:01 AM

Quote:

Originally Posted by golmschenk (Post 4373776)
I know that C/C++ programs usually need to be compiled specifically for the system they are going to be run on. However, I'm wondering if there's a way to get around this. I plan to make a program that preforms very simple manipulation of an image, but I would like to distribute it to people in the form of an exe. Is there an easy way to make the program run on any system without the user needing any knowledge of how to compile a C/C++ program? Can I easily package the program in a way that it can self compile?

Thanks for putting up with this question. I'm not used to making programs for people on windows or those who I won't expect to use a make file.

Impossible. Use java.

Sergei Steshenko 06-02-2011 09:09 AM

Quote:

Originally Posted by SigTerm (Post 4373988)
Impossible. Use java.

Why impossible ? Java is just a program - as well as g++. So, instead of using Java one can supply g++ and all the needed sources and libraries - at least in theory.

paulsm4 06-02-2011 09:39 AM

Quote:

So, instead of using Java one can supply g++ and all the needed sources and libraries - at least in theory.
Just like "instead of chewing them, one can eat string beans through your nose." At least in theory ;)

SigTerm 06-02-2011 09:58 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4374109)
Why impossible ? Java is just a program - as well as g++. So, instead of using Java one can supply g++ and all the needed sources and libraries - at least in theory.

Well, in practice, you'll have to severely limit number of supported platforms and impose strict minimal system requirements, and you still will end up with multiple versions of same program. You can't make an exe that will run anywhere - on any system + any platform + any architecture, with self-compilation you'll run into problem with different compiler versions. Also, last time I checked there is no portable version of g++ that'll run anywhere.

Sergei Steshenko 06-02-2011 10:01 AM

Quote:

Originally Posted by SigTerm (Post 4374158)
Well, in practice, you'll have to severely limit number of supported platforms and impose strict minimal system requirements, and you still will end up with multiple versions of same program. You can't make an exe that will run anywhere - on any system + any platform + any architecture, with self-compilation you'll run into problem with different compiler versions. Also, last time I checked there is no portable version of g++ that'll run anywhere.

Of course I can - that's for GNU autotools and cross-platform toolkits like Qt, WxWidgets, gtk+ exist for.

MTK358 06-02-2011 10:03 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4374161)
Of course I can - that's for GNU autotools and cross-platform toolkits like Qt, WxWidgets, gtk+ exist for.

An executable that relies on Qt doesn't run everywhere.

Source code using Qt can be compiled to an executable for any platform.

Sergei Steshenko 06-02-2011 10:04 AM

Quote:

Originally Posted by paulsm4 (Post 4374134)
Just like "instead of chewing them, one can eat string beans through your nose." At least in theory ;)

Should I remind that "C" interpreters (not compilers) exist ? Then, for example, we translate C++ int "C" using LLVM and interpret the resulting "C" code.

SigTerm 06-02-2011 11:10 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4374161)
Of course I can - that's for GNU autotools and cross-platform toolkits like Qt, WxWidgets, gtk+ exist for.

That's what I was talking about when I said "impose system requirements".
It is possible to make a package that'll "probably" compile and run on a platform that has autotools + Qt + certain version of compiler(i.e. on platform that contains certain strictly specified packages/software), but you can't make a program, that'll "selfcompile" anywhere - simply because "every possible platform" also includes "platforms without autotools/Qt/compiler". That's why it is impossible to implement this project in general case.

Sergei Steshenko 06-03-2011 02:41 AM

Quote:

Originally Posted by SigTerm (Post 4374716)
That's what I was talking about when I said "impose system requirements".
It is possible to make a package that'll "probably" compile and run on a platform that has autotools + Qt + certain version of compiler(i.e. on platform that contains certain strictly specified packages/software), but you can't make a program, that'll "selfcompile" anywhere - simply because "every possible platform" also includes "platforms without autotools/Qt/compiler". That's why it is impossible to implement this project in general case.

But the project can be distributed with GNU autotools, Qt (or another GUI toolkit) in spurce form, compiler as binary. They are just files. That's why it is possible to implement this project in general case.

SigTerm 06-03-2011 07:13 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4374821)
But the project can be distributed with GNU autotools, Qt (or another GUI toolkit) in spurce form, compiler as binary. They are just files. That's why it is possible to implement this project in general case.

It is still not possible. To do so, you'll need to limit a number of supported platforms, distributions and architectures. Qt won't build on architecture without X, and compiler binary will run only on compatible platforms. It is possible to support a certain number of platforms(list of platforms). It is NOT possible to support every possible platform/distro.


All times are GMT -5. The time now is 02:59 AM.