Set up Eclipse C++ compiler without auto-install or altering System Path on Windows

后端 未结 1 968
不知归路
不知归路 2021-01-07 12:44

I am trying to install a C++ compiler on Eclipse without altering the Path variables as I can\'t, the machine has limited rights. Eclipse obviously runs fine, it\'s the bui

相关标签:
1条回答
  • 2021-01-07 12:47

    It looks like you're trying to build a simple hello world program using Eclipse/CDT and a development environment and using mingw as the compiler tool chain. I was able to get this working just now without modifying my system path environment variable. This is what I did:

    • I already had Eclipse 3.5 (Galileo) installed with CDT
    • Installed MinGW to C:\MinGW (I assume you already had this done). Make sure the mingw-make component is installed (it's not installed by default, I had to check the box to install this component).
    • Create a new empty makefile project, add main.c, write hello world code (as you say this isn't the problem so I'm skipping detail here), add a new file called "makefile" and fill it in.

    Contents of my main.c file

        #include   
        int main()  
        {  
            printf("Hello World!");  
            return 0;  
        }  
    

    Contents of my makefile:

        all:  
            gcc -o HelloWorld.exe main.c 
    
    • Open the project properties; Under C/C++ Build uncheck the "use default build command" and change the build command to "mingw32-make".
    • Under "C/C++ Build/Environment" add a new PATH variable with C:\Mingw\bin in the path
    • Under "C/C++ General/Paths and Symbols" add C:\mingw\include as an include path.

    After doing this, my project built successfully and produced a HelloWorld.exe exectuable in my project.

    Another option that doesn't require adding a PATH variable to the system or project properties, or adding the include path to the project properties is to simply gives full path info to the commands in the makefile. For small projects this is manageable. Here's an example makefile:

    Contents of makefile:

        all:  
            c:\mingw\bin\gcc -o HelloWorld.exe -I c:\mingw\include main.c 
    

    Of course you'll also have to change the build command from simply "mingw32-make" to "C:\mingw\bin\mingw32-make" as well.

    Another downside of this approach is that the CDT code parser will not be able to locate include files so you'll have warning in the editor to that effect.

    0 讨论(0)
提交回复
热议问题