clang: Compiling C sources with Visual Studio

NppExec
Anonymous
2012-05-20
2013-05-21

  • Anonymous
    2012-05-20

    Hey,

    I had spent a good couple of hours getting this to work. Finally, I was able to coax NppExec, clang and Visual Studio to work together and let me compile my C snippets. As per the NppExec documentation:

    Have a suggestion?
    Visit NppExec's forum and let me know.

    The following script along with (compile_or_run described in the documentation) worked for me:

    // run@.cpp.txt
    // setting NppExec's internal (user) variables
    SET VCBASE=C:\Program Files\Microsoft Visual Studio 10.0
    SET VCDIR = $(VCBASE)\VC
    SET VSCOMMON = $(VCBASE)\Common7\IDE
    SET MSSDK = C:\Program Files\Microsoft SDKs\Windows\v7.0A
    // saving previous values of environment variables (just in case)
    SET PATH_0 = $(SYS.PATH)
    SET INCLUDE_0 = $(SYS.INCLUDE)
    SET LIB_0 = $(SYS.LIB)
    // setting NppExec's child process'es environment variables
    ENV_SET PATH = $(VCDIR)\bin;$(MSSDK)\bin;$(VSCOMMON);$(SYS.PATH)
    ENV_SET INCLUDE = $(MSSDK)\include;$(VCDIR)\include;$(SYS.INCLUDE)
    ENV_SET LIB = $(MSSDK)\lib;$(VCDIR)\lib;$(SYS.LIB)
    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ///! NOTE: change the following to the folder where your clang binary resides
    SET clangc = D:\llvm_workspace\llvm\build\bin\Debug\clang.exe
    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    SET obj = $(CURRENT_DIRECTORY)\$(NAME_PART)
    // run clang
    "$(clangc)" "$(FULL_CURRENT_PATH)" -o "$(obj).exe"
    cmd /c "$(obj).exe"
    UNSET obj
    UNSET clangc
    // restoring previous values of environment variables
    ENV_SET PATH = $(PATH_0)
    ENV_SET INCLUDE = $(INCLUDE_0)
    ENV_SET LIB = $(LIB_0)
    UNSET VCBASE
    

    Things to note: I am using Visual Studio 2010 (installed in C:\Program Files\) on a 32-bit Windows 7 box with NppExec 0.4.2.1 and my clang 3.0 binaries reside at D:\llvm_workspace\llvm\build\bin\Debug\ (built with Visual Studio 2010). You will need to change the appropriate paths in the script of course depending on your installation.

    Hope this helps someone in near future.

    Cheers!

     
  • DV
    DV
    2012-05-21

    Thanks, I'll consider to include this into the help file.

     
  • DV
    DV
    2012-05-23

    Done. Included in the Manual, section 4.7.3 (comes with NppExec v0.4.3).