Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse C/C++ project on Bash on Ubuntu on Windows

I've installed Eclipse Neon (v4.6). Also, I have "Bash on Ubuntu on Windows" (Sept '16). I installed gcc and gdb for compiling and debugging in C. I tested them on terminal and they're running.

I'm trying to use Eclipse to create a new C project but in the compiler selection stage it doesnt give me the option to use the "Bash on Ubuntu on Windows" compiler.

Is there any way to solve my problem?

like image 768
Xenophon Kitsios Avatar asked Sep 23 '16 23:09

Xenophon Kitsios


4 Answers

We use Eclipse and a makefile project. I configured Eclipse by adding an "external builder" - and use the following script:

-c "cd `echo '${project_loc}' | sed  -e 's/C:/\/mnt\/c/g' -e 's/\\\\/\//g'` && make -f path_to_makefile/makefile

The "cd" and sed trick is to convert from Eclipse "C:\" to Windows Subsystem for Linux "/mnt/c/" and replace "\" with "/"

Make now executes in the project location as defined by ${project_loc}

I still have not figured out how to execute gdb on Linux. But at least compile+link (and execute unit tests as defined in my makefile) is now leveraging the full speed of the native Ubuntu toolchain...

like image 70
espenalb Avatar answered Nov 13 '22 00:11

espenalb


I have some better way... You can add new user terminal and give "Ubuntu.exe" location in eclipse under Local terminal setup as shown in screen shot.

in my case directory is ...

  • C:\Users\MyuserName\AppData\Local\Microsoft\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc

if eclipse not able to select ubuntu16.4.exe, then write manually in path. as shown in image. see this...

Now just click on Apply and close. Open terminal (Ctrl+Alt+Shift+T) and select Ubuntu terminal.

Now, Navigate to source directory through terminal and compile you project. Enjoy...

like image 27
Logan859 Avatar answered Nov 12 '22 22:11

Logan859


Because Bash/WSL is pretty new and the ability to correctly invoke Linux commands from outside Bash (using bash.exe -c ...) is not well understood by many dev tools (yet), you may have to do some work to define custom tasks/actions to call the necessary bash.exe -c "gcc ..." commands that you want to invoke.

However, you should absolutely be able to write/configure a makefile (or, perhaps even better, a CMake file) which can switch paths to lib/include/tools/etc. based on environment and then build smoothly on Windows or in Linux.

This very scenario has sparked an idea for a cool blog post that I'll work on and publish to our blog https://blogs.msdn.microsoft.com/commandline in the next week or two :)

HTH.

like image 5
Rich Turner Avatar answered Nov 12 '22 23:11

Rich Turner


I think the best way to use the wsl for programming in C/C++ is like Microsoft does it. Visual Studio use ssh to connect to linux environment for "C++ for Linux Development". So, in our case we can set up openssh server on wsl, connect to localhost from your IDE and start remote project.

  • Eclipse and NetBeans supports remote projects.
  • Clions I think not.
  • Here are Microsoft's instruction on how to configure Visual Studio and wsl: https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/

May 2017

like image 4
Xenophon Kitsios Avatar answered Nov 12 '22 22:11

Xenophon Kitsios