How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010?

后端 未结 3 612
轻奢々
轻奢々 2021-02-01 11:13

My teacher is horsed to use Visual Studio 2010 by the school, because they don\'t want to bother installing anything new. I\'ve been using Visual Studio 2015

3条回答
  •  隐瞒了意图╮
    2021-02-01 11:44

    Write a .lua script for premake5 - https://premake.github.io/ How to can be found here: https://github.com/premake/premake-core/wiki

    And then simply create project for specific visual studio using visual studio version from command line - for example like this:

    premake5 --file=myproject.lua vs2015
    premake5 --file=myproject.lua vs2010
    

    Typical script looks like this:

    -- If visual studio version is not specified from command line - use vs2013
    if _ACTION == nil then
        _ACTION = "vs2013"
    end
    
    buildvsver = _ACTION
    
    --
    -- I typically use "_vs2013" suffix so autogenerated projects won't conflict with each other.
    --
    solution ( "MyOwnSolution" .. "_" .. buildvsver)
        platforms {  "x32", "x64" }
        configurations { "Debug", "Release" }
        objdir (  "obj/" .. buildvsver)
    
    project ("MyOwnProject" .. "_" .. buildvsver)
        kind     "SharedLib"                -- http://industriousone.com/kind: ConsoleApp | SharedLib | StaticLib | WindowedApp
        platforms {  "x32", "x64" }
        language "C++"
        targetdir ("bin/%{cfg.buildcfg}_%{cfg.platform}_" .. buildvsver)
    
        -- If you use managed code
        flags { "Managed" }
    
        flags { "MFC" }
        flags { "Unicode" }
    
        -- Add dependency on another project:
        -- dependson { "OtherProject" .. "_" .. buildvsver }
    
        -- If you use managed code - you can specify .net framework version.
        framework "4.0"
    
        files {
            "mysource1.cpp",
            "myheader1.h",
            "myheader2.cpp",
        }
    
        links {
            -- Some of dependent libraries
            "dbghelp.lib",
            "delayimp.lib"
        }
    
        -- Force to delay load some .dll
        -- Custom / advanced flags.
        linkoptions { "/delayload:dbghelp.dll " }
        linkoptions { "/delayload:mscoree.dll " }
    
        configuration "*"
            -- I typically use 'ReleaseRuntime' - that's debug = release configuration. 
            -- No special .dll's are needed even for debug version of your application
            flags { "NoRuntimeChecks", "ReleaseRuntime" }
    
            -- Debug symbols.
            flags { "Symbols" }
    
            -- Executable name without _vs2013 prefix.
            targetname ( "MyOwnProject" )
    
            -- C++ defines for both - release and debug configurations.
            defines { "NDEBUG", "_CRT_SECURE_NO_WARNINGS", "WIN32", "WINVER=0x0600", "_WIN32_WINNT=0x0600" }
    
            -- debugcommand "customExeToLaunch.exe"
    
            -- Custom post build steps.
            -- postbuildcommands { "call $(ProjectDir)projexport.bat $(PlatformName) $(TargetPath)" }
    
        configuration "Release"
            -- Only difference from debug - is optimizations for speed.
            optimize "Speed"
    
            -- Can debug in release.
    
            --
            -- Enhance Optimized Debugging
            -- https://randomascii.wordpress.com/2013/09/11/debugging-optimized-codenew-in-visual-studio-2012/
            -- https://msdn.microsoft.com/en-us/library/dn785163.aspx
            --
            buildoptions { "/Zo" }
    
    
    project ("TestMyProject" .. "_" .. buildvsver)
        platforms {  "x32", "x64" }
        kind     "ConsoleApp"
        language "C#"
        targetdir ("bin/%{cfg.buildcfg}_%{cfg.platform}_" .. buildvsver)
        framework "4.0"
    
        links {
            "System",
            "System.Core",
            "System.Data",
            "System.Drawing",
            "System.Windows.Forms",
            "System.Xml",
            "MyOwnProject" .. "_" .. buildvsver
        }
    
        files    { 
            "TestMyProject.cs",
        }
    
        configuration "*"
            targetname ( "TestMyProject" )
            flags { "Symbols" }
            defines { "DEBUG" }
    

    After you reach some sort of understanding how things works - you can even create for .lua itself it's own custom build step to launch premake5, or even to customize project generation - like create lua functions which helps you more advanced projects.

    Please note that I'm using a lot of advanced stuff which you might not need (Most of my projects are compiling for 64 and 32 bit cpu's, and so on...) - may be it makes sense to start from zero than to copy config shown by me. Then you will have understanding how things works.

提交回复
热议问题