0

Can I code C++ application for Linux OS on Windows using Eclipse?

If it is possible, what are the settings I have to do in Eclipse?

Thanks in advance.

howlger
  • 31,050
  • 11
  • 59
  • 99
user566
  • 97
  • 1
  • 12
  • 2
    The keyword you are looking for is "Cross Compile". It's been a while since I've set this up (because I usually spin up a Linux virtual machine) and it's probably different (and easier) now. First thing you do is track down and install the compiler you want. Eclipse has plug-ins for GCC, so you may want to stick with that. Then when you create a new C++ project, you select Cross GCC and... Why the hell Am I writing this in a comment? Back in a few minutes with an answer and pictures. – user4581301 Aug 04 '17 at 05:17

2 Answers2

2

First off, find a compiler. I can't help with this one, but a websearch for "Windows to Linux Cross Compiler GCC" will probably help. So should browsing cygwin.

Good coverage here: C++ cross-compiler from Windows to Linux

That sends us to Eclipse to build a new project which I'm assuming you already know how to do. That gets you here:

enter image description here

which that leads here:

enter image description here

Nothing to see on that panel, so next to

enter image description here

Fill in the two text boxes and click finish. Path is kind of obvious, Where is Eclipse going to find the compiler and tools and the other is a bit weird. Because once you go down this path, you tend to have many compilers, they have to get different names to prevent confusion. So you might have linux-mips32-g++ and linux-i386-g++ and qnx-arm-g++ all on the same machine. Eclipse wants to know what to slap in front of g++ and the other tools.

There will be much more fun setting up remote debugging, but that's another question, I think.

user4581301
  • 33,082
  • 7
  • 33
  • 54
0

C++ compilers are available for Linux as well as for Windows, so there is no such thing as "C++ application for Linux". Just write in standard C++, don't use platform-specific features (i.e. winapi calls) and don't use any libraries you can't build on Linux or any other target platform.

Given the above, you will just need to compile you program (which was initially written in Windows environment) on Linux, and it will run the same way. If you use latest language features (C++17 and/or expeirmental), you might get some compilation errors, which are very easy to fix. Something like #ifdef _WIN32 is your last resort when dealing with them.

Surely, you don't need any special settings. The only advice is to use a cross-platform build system. For example, CMake can do the lion's share of dirty work, while allowing you to write any platform-specific build settings in neat if(MSVC) ... endif() blocks.

Sergey
  • 7,985
  • 4
  • 48
  • 80