This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++ Portability between Windows and Linux
i am new to c++ programming and i dont really know much about it
i am running linux (ubuntu) in my desktop and my laptop is running windows but it has charger problems.. anyway, what i want to do is to program softwares in linux and run them in my laptop (windows)... so my question is is there any difference between programming c++ in linux and windows and if the generated program only runs on linux, can i re-compile the code that has been compiled and ran fine in linux??
i have looked in google but i didnt really get useful informations!
C++ code can be compiled quite happily on Linux, Windows and a gazillion other platforms. Where you will have problems is with the libraries that you link to. So long as you stick to the standard library of C++ or highly portable libraries like boost then you should have relatively few issues. If you link to a library that is only available on one of the platforms, then you will hit trouble.
Related
I want to develop cross-platform programs using C++. I found out that I can easily develop programs for Linux under Windows using remote development in Visual Studio using e.g. WSL. When I searched how to develop programs for Windows under Linux, I found that I can use mingw-w64 to do it. My question is whether the development using mingw-w64 is as good as the development of Windows programs under Windows. What do I mean by "as good as":
absence of errors
no limitation of using libraries
no problems with debugging
etc.
In short, I want the development and most importantly the resulting programs to be the same as in development under Windows.
Globally, I want to choose my main OS for programming: Linux or Windows. I prefer Linux but am afraid that it will somehow limit my ability to program cross-platform solutions. Currently, I'm programming only in Python and didn't have any problems but I'm learning C++ and I want to use it professionally later in life.
UPD: Also, can I use remote development for Windows under Linux? I would be glad to see some articles, videos, tutorials. Because if I search it, Google outputs the results for development for Linux under Windows - it doesn't understand that I need it to be vice versa.
I'm using Fedora 29, and I've been happily using sublime text to compile/build and run C++ code that runs on this machine.
I now realize that the compiled program is not portable. It will only run on Linux. It won't run on Mac or Windows.
After some research, I found out that Mac uses a different format than Linux does. This info was backed up after repeating the experiment as well as compiling the same source code on Mac (which worked fine).
Question
Is there a way to use sublime text on Linux to compile code (C++ or other) that will run on other operating systems (i.e MacOS and Windows). I do not mind compiling the code 3 times, one for Windows, one for Mac, and one for Linux.
Notes
Note1: I want the code to be compiled in C++11!
Note2: I have already added the C++11 build, and have been using it.
Edit
My post is different from this question here, because I already know why I need to compile in different formats, therefore that is not my question. My question is "how can I do this in sublime text?" or, if that is not possible, "is there an app that will let me do this without leaving my OS?" Thanks in advance! PS: I do not mind compiling the code 3 times, one for Windows, one for Mac, and one for Linux.
Why do we need to compile for different platforms (e.g. Windows/Linux)?
First of, I am very new to programming, but took an interest in it. I have successfully built a C++ Console program for Windows which is a simple Database program, which can edit / delete / input entries.
I am less and less relying on Windows for day to day stuff. I had an old HP Netbook which was impossible to use with Windows, but I put in a Linux Distro and works like a charm.
As I sometimes do use Windows, as well as having built the program to use in Windows, I am wondering if the same code can be used to compile a Linux program? I could use WINE to run it but would prefer running something specific to Linux. Is this possible with the same code or would I have to make another Linux version of it?
I would assume that since you are new to programming, that you did not make the extraordinary effort to make your code portable across platforms. That takes a significant skill set, especially if you are accessing external resources such as a database. So the answer is you will probably have to re-write for Linux, and specifically the database interface.
I guess that you want your C++ code to be compilable both on Linux and on Windows. You'll need operating-system specific compilers for that (a different one on Linux and on Windows).
I am wondering if the same code can be used to compile a Linux program?
The program to compile your C++ code is called a compiler. On Linux you will use GCC as the g++ command (which you could even customize with MELT, but that is not for newbies), or Clang/LLVM as the clang++ command. You'll use a builder like make (see here for why, and this example). Be sure to install a recent version (GCC 4.9 or Clang 3.5 at least in start of 2015) to get good C++11 support. Focus on learning C++11 (or C++14) not some earlier variant (so use a C++11 compiler).
I don't know Windows so I cannot recommend any good C++ compiler for it (but I heard of MinGW, CygWin and of Microsoft Visual C++; look also into recent Clang...).
You might be interested in cross-platform C++ framework libraries like Qt or POCO (and perhaps also Sqlite for database related stuff). They will help you to code some C++ usable on both systems (after recompilation).
BTW, you can always encapsulate your system specific code with preprocessor directives à la #if LINUX ;take care of putting all the OS specific (or OS related) code in a few source files.
It could happen (and I wish that for you) that you get fond & happy of Linux and will, in a few months, prefer to code for Linux only (you'll then install Linux on all your machines). BTW, study the source code of existing free software you like and use on Linux. That will teach you a lot.
The advices I gave here and here are still relevant today when coding on Linux. Read also something about porting & portability, and Advanced Linux Programming.
This question already has answers here:
windows version of the GDB frontend DDD
(5 answers)
Closed 4 years ago.
I heard that there is a graphical debugger by GNU called DDD, which will help to learn C. I have searched DDD for windows 7, but i won't get anything useful. All i saw is DDD on Linux. My question is can i install DDD into Windows 7 ? if so where can i find set up file and other information ?
You can do it installing Cygwin. In this way you can use all the linux GNU Tools under Windows.
Cygwin is a Unix-like environment and
command-line interface for Microsoft Windows. Cygwin provides native
integration of Windows-based applications, data, and other system
resources with applications, software tools, and data of the Unix-like
environment. Thus it is possible to launch Windows applications from
the Cygwin environment, as well as to use Cygwin tools and
applications within the Windows operating context.
Here's the Cygwin installation guide.
First off, because you're learning C try to resist the temptation to depend entirely on your debugger to figure out what's wrong with your code. A debugger assists the brain but shouldn't replace it.
That being said, it might be less ambitious to start with a free IDE+toolchain with a decent debugger that's a bit easier to get up and running than Cygwin & friends.
I've always liked the now opensourced Watcom C toolchain a lot, and it comes with a nice debugger. It's showing its age a bit, but it's still a very capable tool.
Microsoft still offers its Visual Studio Express "lite" version of VS for free. Aside from some restrictions, it's a Visual Studio 2012.
And of course there are the IDE's built mostly around gcc, like Code::Blocks, Eclipse CDT and many others
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Cross platform programming
I've written some code using wxwidgets in c++. But I am not able to compile the same code for both windows and linux. Actually I'm a bit scared by the preprocessor directives generated by code-blocks ide. I wonder if anyone could point out some nice tutorials for learning cross-compilation.
Thanks in Advance
Jvc
If you want to build a cross platform program, you will stumbl across a few kind of problems.
Cross compilers problem
Some compilers are offering non-standard functionalities that might not work on other compiler. You have to make sure that compiler functionnalitie's you use are standard or available on all the compilers you use (An exemple would be the VC++ #pragma that wasn't usable on gcc until version 4.2.1)
Platform specific functions and libraries
Guess what, if you include <windows.h> it won't compile on a linux system (this is madness I know). So you must try to avoid those platform specific libraries/function. If you ever have to use them, try to encapsulate their use and select the specific class you need to compile on different system.
Here is a wonderful guide posted by the Mozilla foundation :
https://developer.mozilla.org/en/C___Portability_Guide
You could have a look at Cross Compiling wxWidgets Applications on Linux (Code::Blocks wiki) and Cross-Compiling Under Linux (wxWiki). There is also a section on cross compiling Windows applications in Brent W. Woodruff C++ Introduction to wxWidgets.