Search code examples
visual-c++mingwinvocation-api

Compile with VC++


I need to convert this gcc build command to VC++

g++ -o launcher.exe launcher.cpp -I C:/JDK/include_jdk -I C:/JDK/include_jdk/win32 -L C:/Program Files (x86)/Java/jre6/bin/client  -ljvm

I don't use VC++ at all (use mingw) and just have to compile this single file. Please, help!


Solution

  • To compile a single file easily in VC++, open up a Visual Studio Command Prompt (you should have a shortcut installed as part of the installation process), and do the following:

    cl launcher.cpp
    

    That will build launcher.exe for you.

    To add specific include paths use the /I option, and to add linker options, you can add them after passing the /link parameter, so for example use /libpath to add a library search path, and then just stick the library names onto the command line:

    cl launcher.cpp /I C:/JDK/include_jdk /I C:/JDK/include_jdk/win32 /link /libpath "C:/Program Files (x86)/Java/jre6/bin/client" libjvm.lib
    

    The output filename, if you're compiling a single .cpp file, will be that filename with a .exe extension, but that's what you seem to want. Otherwise, stick a /out parameter on... but I'll leave that as an exercise for you.

    More information can be found on MSDN.