Getting error while compiling a source file (.C) using the Microsoft Visual C / C ++ compiler via GnuWin32 on Windows 7

I will show you the step as below.

First you download GNUWIN32 .

Then install on windows 7 and set the path to environment.

  • I will make aC source file shown below

    #include <stdio.h>
    int main()
    {
        //FileName: a.C
        printf("Hello World !!! Its works");
        return 0;
    }
    
          

  • I'll make a Makefile . as below

    #MakeFile Source Code... FileName: Makefile
    OBJS: a
    
    #add path visual c/c++ compiler
    PATH=C:/Program Files\ (x86)\Microsoft\ Visual\ Studio\ 9.0/VC
    
    CC: $(PATH)/bin/cl.exe
    
    all: a
    
    a: 
        $(CC) -c a.C
    
    clean:
        rm -rf $(OBJS)  
    
          

  • I am compiling from source. he gets an error.

    Input: C:\Users\*****\Desktop\Test>make
    
    output:
    cc -c a.C
    process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.
    make (e=2): The system cannot find the file specified.
    make: *** [a] Error 2
    
          

Please give me some help on how to generate this code using the Visual C ++ compiler.

+3


source to share


3 answers


PATH

is the wrong name to use in a variable in the Makefile because it is also the name of a variable that lists the paths to look for when looking for other programs. Change it to something else.



+1


source


There is a semantic error in your makefile. You are defining CC as a target, not a variable. Fix it like this:

CC=$(PATH)/bin/cl.exe

      



The key is in the error message process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.

. You can see that it is trying to execute cc

notcl.exe

+1


source


If you look at the vcvars32.bat

one provided by μSoft to set up the environment for the compiler, you can see that it adds several folders to your environment variable %PATH%

.

You can express this %PATH%

minging in make if you like. Something like

export PATH := /cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/IDE:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/BIN:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/Tools:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages:/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.0A/bin:${PATH}:/cygdrive/C/PROGRA~1/MICROS~2.0/VC/redist/DEBUG_~1/x86/MICROS~1.DEB

      

Yes, that's make syntax. It complements any existing %PATH%

prefix and suffix (see What's ${PATH}

in the middle right?).

Note that this is in a cygwin make-ready format. You may need several adjustments. Oh, and don't forget that you cl.exe

need decent settings for %INCLUDE%

, %LIB%

and %LIBPATH%

too.

0


source







All Articles