Visual Studio toolchain in Eclipse for C++

7.4k views Asked by At

I have Eclipse Neon.2 installed for Java, however, I am working on a project that involves JNI so I have had to set up Eclipse for C++. To do this I downloaded the Development Tools for C++ under Help -> Install New Software. My problem is there are no available toolchains available for my C++ project.

Several websites and YouTube videos have suggested that there is a Microsoft Visual C++ toolchain available, such as this SO question and this video, but I have had no success.

Is there a setup stage or plugin I could have missed that is causing it not to be listed?

Setup
Windows 10
Eclipse Neon.2
Microsoft Visual Studio Enterprise 2017 RC

3

There are 3 answers

4
tommybee On BEST ANSWER

Well, I think you should install either windows SDK 7, 8 or Visual C++ 2015 Build Tools.

I tested windows SDK 7 with eclipse neon. You can find a quick installation guide here.

but I don't know what will happen with Visual C++ 2015 Build Tools. This tools is introduced in my blog - even written in korean but with full of images.

Then, you can find my another answer.

Finally, you have two check points comparing with what you have done.

The one is

enter image description here

Anther one is

enter image description here

0
Wr0NG On

Run Eclipse from Developer Command Prompt. If you added all include paths, but <windows.h> could't be resolved and fatal error C1083: Cannot open include file: 'winapifamily.h' occurs then to All configurations and All languages (checkboxes) Project -> Properties -> C/C++ General -> Paths and Symbols -> Include directories -> Add...

  • Program Files (x86)\Windows Kits\8.1\Include\um
  • Program Files (x86)\Windows Kits\8.1\Include\shared

and don't forget Project -> C/C++ Index -> Rebuild

If there is fatal error LNK1104: cannot open file 'kernel32.lib' and ucrt.lib in Project -> Properties -> C/C++ Build -> Settings -> Linker (Link) -> Libraries -> Additional Libpath (/libpath) Add...

  • Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
  • Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x86

or (x64, arm, etc...) for Configuration: All Configurations

Also know, that you could't debug with CDB & through the years Eclipse keeps brand

1
Dana M On

Steps to get Eclipse building "Hello World" with MSVC:

  1. Install Visual Studio (should work with VS 2017, VS 2019, and maybe earlier).
  2. Install Eclipse IDE for C/C++ Developers.
  3. In Eclipse, go to "Help / Install new software...". Under "Work with...", select the CDT software update site.
  4. Under "CDT Optional Features", select "C/C++ Visual C++ Support". Install it and restart Eclipse, then close Eclipse.
  5. From the Windows search/run bar, start "Developer Command Prompt for VS 2019" (or earlier version). You should now have a command window and prompt.
  6. Run "set", and observe that there's a ton of VS-specific environment variables present.
  7. Enter the full program path to Eclipse (e.g. C:\Users\drodgers\eclipse\cpp-2019-12\eclipse\eclipse.exe), and hit Enter. You're now running Eclipse again, but with all the VS environment variables present.
  8. Create a new C++ Managed Build project. Enter a project name, select "Hello World C++ Project", and select Microsoft Visual C++ as the toolchain. Finish creating the project.
  9. In the main source file, you should see an orange squiggle under #include <iostream> and red squiggles under std, cout, and endl because Eclipse doesn't know where to find all the include files. Let's fix that.
  10. In Project Explorer, right-click on the project name, select "Properties", then select "C/C++ General / Paths and Symbols". With the "Includes" tab in view, select "Add...", you'll get an "Add directory path" dialog. Click "Variables...", wait a moment, then select "VCToolsInstallDir", which will fill ${VCToolsInstallDir} in the dialog (or just type it). Then append /include so that it reads ${VCToolsInstallDir}/include. (Backslash works too... but see below.) Check the "Add to all configurations" and "Add to all languages" boxes. Your dialog should look like this:

Setting the include path to VC include files

  1. Click OK, then click Apply and Close. If you're prompted to rebuild the index, say Yes. The orange squiggle for the include should go away, and once the index is rebuilt, the red squiggles should go away, too (do a manual index rebuild if necessary - right-click project, select "Index / Rebuild".
  2. Right-click your project, and select "Build". It should now build successfully., like so:
21:12:43 **** Rebuild of configuration Debug for project wibble ****
Info: Internal Builder is used for build
cl /c /EHs /MD /Zi "/IC:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\\\include" /nologo "/Fosource\\wibble.obj" "..\\source\\wibble.cpp" 
wibble.cpp
link /debug /nologo /OUT:wibble.exe "source\\wibble.obj"

21:12:44 Build Finished. 0 errors, 0 warnings. (took 1s.594ms)
  1. Verify that you can run your new executable by browsing to your project location, going into the "Debug" directory, launching a command prompt, and running the EXE that's there. You should see "Hello World" appear in your console window.
  2. To further simplify your launch process, create a subdirectory under your user directory (e.g. C:\Users\drodgers\batch), create eclipse.bat containing the full path to Eclipse, and then edit your environment variables to add the new directory to your user variables' "Path" setting. Now when you run the Dev Command Prompt, you only have to type eclipse to launch Eclipse.

(Disclaimer: I can't take full credit for this answer, because I found the guts of it here. But I couldn't find a SO post that offered this solution, so I'm posting it myself.)

EDIT: Been playing a bit more, and there's some quality of life stuff that needs to be added. For whatever reason, MS doesn't include ctype.h or a number of other "standard" headers in its main include directory, so items like isxdigit() will be flagged red as Function isxdigit() could not be resolved. To fix this:

  1. As referenced in a comment to the accepted answer for this question, for VS 2017 or 2019, you should install the "Windows Universal CRT SDK" component using the VS Installer app.
  2. Close Eclipse, relaunch the VS 2019 Developer Command Prompt, and relaunch Eclipse.
  3. In your Eclipse C++ project, under "Paths and Symbols", specify these two directories: ${VCToolsInstallDir}/include and ${WindowsSdkDir}/Include/${UCRTVersion}/ucrt. Note I used forward slashes; they work fine with Eclipse on Windows systems. If I use backslashes in that second path instead, Eclipse starts invoking substitution escapes and you won't get the right path, so don't do that.

Now you shouldn't have any unresolved symbols in your editor (at least for standard C/C++ stuff).