News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Win8 sdk how to?

Started by jcfuller, December 09, 2012, 02:10:25 AM

Previous topic - Next topic

jcfuller

I'm not sure if this is the right place for this as it's a VC++ inquiry.

I ask here on this forum as it has, in my opinion, the most knowledgeable and diverse group of programmers anywhere.

I have recently installed Windows 8.

I have a Win7 machine with MS SDK 7.0A and Visual C++ 2010 express installed.
I installed this so long ago ( along with my dwindling mental capacity) I have no idea how I did it?
SDK first then VS2010 or the other way around?
This is working just fine with this bat file.

Note: VS100COMNTOOLS was added to global environment. by who or what -> no idea?
VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\



setlocal
@rem Created with Bldbat v.3.0.0 for Microsoft Visual Studio 2010 X86 (Console)
@ECHO OFF

REM get just file name. RadAsm3 passes complete path with non project files
REM ----------------------------
SET F=%~n1
REM ----------------------------

IF NOT EXIST %F%.cpp GOTO usage
CALL "%VS100COMNTOOLS%vsvars32.bat"
SET MYSDKBINPATH="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"
SET MYSDKLIBPATH="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib"
SET MYSDKINCLUDEPATH="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include"

REM --------------------------------------------------------------
REM always use the %F%.rc file in the Res Directory if it exists
REM this should handle both projects and individual files with resources

IF EXIST res\%F%.rc (
  ECHO Compiling resources.....
  cd res
  GoRc /r %F%
  SET VRES=res\%F%.res
  cd ..
) ELSE (
  IF EXIST %F%.rc (
    ECHO Compiling resources.....
    GoRc /r %F%
    SET VRES=%F%.res
  )
)
REM --------------------------------------------------------------



ECHO Compiling "%F%.cpp"..........
"%VCINSTALLDIR%\bin\cl.exe" /c /O1 /Gd /W1 /EHsc /MT /Zc:auto- /D_WIN32_IE=0x0501 /I%MYSDKINCLUDEPATH% "%F%.cpp"
ECHO Linking ................
"%VCINSTALLDIR%\bin\link.exe" /RELEASE /MACHINE:IX86 /LIBPATH:%MYSDKLIBPATH% /SUBSYSTEM:CONSOLE "%F%.obj" %VRES% %2 %3 %4 %5 %6 %7 %8 %9 /OUT:"%F%.exe"
ECHO Finished!
IF EXIST "%F%.obj" del "%F%.obj"
IF EXIST "%F%.res" del "%F%.res"
GOTO done
:usage
ECHO **************************************************************
ECHO  Usage:  VS100C.BAT MainFile  ExtraFile1 ExtraFile2 ExtraFile3
ECHO  Note:   ExtraFiles can be .libs, .res , .obj
ECHO  Use this batch file to create console mode program
ECHO **************************************************************
:done
endlocal




#1  Is there a (free) way to compile to a 64bit app using a Microsoft C++ compiler on either Win7/8?

#2 What do I need on Win8 (and which order) for the same approach as I use above on Win7? Win8 sdk?
  I think I read somewhere there were problems in the order installed?

The reason:
  My passion of late is my fork of bcx, bc9, a basic syntax to c/c++ source translator.
I prefer using the MinGW gcc/g++ compiler as I can create 32/64 bit apps and dlls with just a -m32/-m64 passed to the compiler using the
same source. I have recently been working out some quirks  pertaining to calling conventions in dll creation and calling
functions in the dlls.

The creation of the dll with MinGW generates a def.
I then use the visual c++ lib utility to create an import library.
lib /machine:X86 /def:testdll.def -> testdll.lib

I then can compile the app that uses the dll created with MinGW g++

What I can't do is test this with a VC++ 64bit app.
I assume the X86 in the lib call would be X64

Attached is the c++ source for the app and the dll. Also in the zip is the g++ created 64bit dll,def.

If someone has the resources to compile the app with cl to 64bit and test with the included dll I would be grateful but I would
prefer finding a solution where I could find a recent MS c++ compiler that would compile to 64bit.

Thank you,

James



dedndave

hi James
it would seem logical to install the compiler, then the SDK

however, the SDK install may screw up some environment variables
so, doing it the other way around would actually seem correct - lol

you can set system-wide environment variables via the control panel
or the windows 8 version of a control panel   :biggrin:  you may have to sign in with admin privileges
i have no experience with windows 8, and little with windows 7
but, i know that MS compilers have always relied heavily on the environment table

here is what i would do if i were in your shoes...
i would look at the environment variables on the machine that is working
in fact, open a command prompt window
SET >ENV.TXT
that will create a text file with all the variables
then - copy that file over to the windows 8 machine
from there, you can use copy/paste to set up the compiler-related variables in windows 8
of course, you may have to modify some of the path names slightly

anta40

Hi James,

I only have experience with Win 7 (now using Win 7 Pro 64).

I don't have VS installed (only Win 7 SDK). The easiest way to compile program is by running the Windows SDK 7.1 Command Prompt (should be available in Start -> All Programs -> Microsoft Windows SDK 7.1). By the default, the output is x64 debug built. If you want to change it to x86 release or x64 release, for example, run C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd, with paramters "/x86 Release" or "/x64 Release"

BTW, the 64-bit executable is attached. Please give it a try.

anta40

BTW, here's the steps:
1. Run "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd /x64 Release". Now you are ready to compile 64-bit apps
2. Run "cl test_ccb_cdll_64.cpp ccb_cdll_64 /Fetest_ccb.exe". The result is test_ccb.exe.
The /Fe option is used to specify the executable's name


jcfuller

I think now I know what I did on my main programming box.
All I installed was VS2010 so I do not have the full win7 sdk.

I do have the Win7 sdk  on the machine I upgraded to Win8 but I'm not going there yet.

Where do I go to get the latest Win7 SDK?

I'm pretty sure I read the Win8 SDK does not include any compilers?

James

CommonTater

If you are installing VC++ express edition you only get the 32 bit compiler with it.
If you install the Win7 SDK from HERE  You will get both 32 and 64 bit compilers.

You want to put in Visual Studio (with VC++) first, then the SDK... so VS doesn't clobber the SDK's compilers.

Hooking VC++ up to the SDK's compilers is a bit of work... some advice HERE  ... but it is doable.




jcfuller

anat40,
  Thank you.
  I uninstalled vc 2010 express. Then installed Win7.1 sdk.
I was a bit confused at first because it installed Microsoft Visual Studio 10.0 in Program Files (x86) but all worked just like you said.

Now I need to figure out how to shell to the SDK command prompt passing it the parameters I want.

Tater,
  I have no need for Visual Studio so it should be a lot simpler.

James

jcfuller

anata40,
  As I experimented further I discovered I could not compile the ccb_cdll_64.cpp (included in the above zip) with cl to create the dll.
Any hints?

James

anta40

Hi James,

Does this work as you expect?
Quotecl.exe /D_USRDLL /D_WINDLL ccb_cdll_64.cpp /link /DLL /OUT:ccb_cdll_64.dll

jcfuller

anta40,
  I finally got your name correct :)

Excellent.
dll and lib created just fine.
Just a bit confused on the "/out:ccb_cdll_64.exe" line?


C:\BcxRadAsm3\Bcx\Examples\dll\TestVc>cl.exe /D_USRDLL /D_WINDLL ccb_cdll_64.cpp
/link /DLL /OUT:ccb_cdll_64.dll
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

ccb_cdll_64.cpp
ccb_cdll_64.cpp(256) : warning C4805: '==' : unsafe mix of type 'BOOL' and type
'bool' in operation
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:ccb_cdll_64.exe
/DLL
/OUT:ccb_cdll_64.dll
ccb_cdll_64.obj
   Creating library ccb_cdll_64.lib and object ccb_cdll_64.exp


Now to go a searching on how to produce the import library for MinGW.
I've read about it at couple of different places, just need to find it again.

Thanks again for your help.

James

jcfuller

Well I have had pretty good luck thanks to anta40 so I thought I'd pass it along.
Two batch files for creating 32/64 bit apps/dlls with the Microsoft C++ compiler.

On Win7 64 I only needed the Win 7.1 SDK

On Win8 I installed both Visual Studio 2012 Express and The Win8 SDK. I may not have needed the Win8 SDK as it does not have compilers.

James


Win7 SDK


@setlocal

@ECHO OFF

REM get just file name. RadAsm3 passes complete path with non project files
REM ----------------------------
SET F=%~n1
REM ----------------------------

IF NOT EXIST %F%.cpp GOTO usage

REM I have this set in RadAsm3 which calls this bat file.
REM unComment so we can find SetEnv.cmd
REM SET PATH=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\;%PATH%


IF [%2]==[] GOTO usage
IF [%3]==[] GOTO usage
SET BUILD=%4
IF [%BUILD%]==[] SET BUILD=Release


REM Set up the environment for compiling.
REM parameter 2 -> X86 or X64
REM parameter 4 -> Release or Debug
REM parameter 3 -> con or gui or dll

CALL SetEnv.cmd /%2 /%BUILD%


IF /I [%3] == [CON] (
  SET SUBSYS= /SUBSYSTEM:CONSOLE
  SET FTYPE="Windows Console App"
)

IF /I [%3] == [GUI] (
  SET SUBSYS=/SUBSYSTEM:WINDOWS
  SET FTYPE="Windows Gui App"
)

IF /I [%3] == [DLL] (
  SET SUBSYS=/DLL
  SET FTYPE="a Windows DLL"
)


REM --------------------------------------------------------------
REM always use the %F%.rc file in the Res Directory if it exists
REM this should handle both projects and individual files with resources



IF EXIST res\%F%.rc (
  ECHO Compiling resources.....
  cd res
  Rc %F%
  SET VRES=res\%F%.res
  cd ..
) ELSE (
  IF EXIST %F%.rc (
    ECHO Compiling resources.....
    Rc %F%
    SET VRES=%F%.res
  )
)

REM --------------------------------------------------------------
ECHO Compiling "%F%.cpp" To %FTYPE%
IF /I [%3]==[DLL] (
cl.exe /D_USRDLL /D_WINDLL "%F%.cpp" %VRES% /link /DLL /OUT:"%F%.dll"
) ELSE (
cl.exe  %F%.cpp /Fe%F%.EXE %WIN_VER% %VRES% %SUBSYSTEM% %5 %6 %7 %8
)

ECHO Finished!
IF EXIST "%F%.obj" del "%F%.obj"
IF EXIST "%F%.res" del "%F%.res"
GOTO done
:usage
ECHO **************************************************************
ECHO  Usage:  VC.BAT MainFile  [x86  x64] [con  gui  dll] extra files
ECHO  Note:   ExtraFiles can be .libs, .res , .obj
ECHO **************************************************************
:done
endlocal
exit



Win8 with VS 2012 Express


@setlocal

@ECHO OFF
:: -----------------------------------------------------------------
:: Batch file to compile c++ applications using Visual Studio 2012
:: and the Win8 sdk

REM get just file name. RadAsm3 passes complete path with non project files
REM ----------------------------
SET F=%~n1
REM ----------------------------

IF NOT EXIST %F%.cpp GOTO usage


IF [%2]==[] GOTO usage
IF [%3]==[] GOTO usage
REM SET BUILD=%4
REM IF [%BUILD%]==[] SET BUILD=Release


REM Set up the environment for compiling.
REM parameter 2 -> x86 or x86_amd64
REM parameter 3 -> con or gui or dll

CALL "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" %2

IF /I [%3] == [CON] (
  SET SUBSYS= /SUBSYSTEM:CONSOLE
  SET FTYPE="Windows Console App"
)

IF /I [%3] == [GUI] (
  SET SUBSYS=/SUBSYSTEM:WINDOWS
  SET FTYPE="Windows Gui App"
)

IF /I [%3] == [DLL] (
  SET SUBSYS=/DLL
  SET FTYPE="a Windows DLL"
)


REM --------------------------------------------------------------
REM always use the %F%.rc file in the Res Directory if it exists
REM this should handle both projects and individual files with resources



IF EXIST res\%F%.rc (
  ECHO Compiling resources.....
  cd res
  Rc %F%
  SET VRES=res\%F%.res
  cd ..
) ELSE (
  IF EXIST %F%.rc (
    ECHO Compiling resources.....
    Rc %F%
    SET VRES=%F%.res
  )
)

REM --------------------------------------------------------------
ECHO Compiling "%F%.cpp" To %FTYPE%
IF /I [%3]==[DLL] (
cl.exe /D_USRDLL /D_WINDLL "%F%.cpp" %VRES% /link /DLL /OUT:"%F%.dll"
) ELSE (
cl.exe  %F%.cpp /Fe%F%.EXE %WIN_VER% %VRES% %SUBSYSTEM% %5 %6 %7 %8
)

ECHO Finished!
IF EXIST "%F%.obj" del "%F%.obj"
IF EXIST "%F%.res" del "%F%.res"
GOTO done
:usage
ECHO **************************************************************
ECHO  Usage:  VC.BAT MainFile  [x86  x64] [con  gui  dll] extra files
ECHO  Note:   ExtraFiles can be .libs, .res , .obj
ECHO **************************************************************
:done
endlocal
exit


CommonTater

Quote from: jcfuller on December 09, 2012, 07:39:48 AM
I have no need for Visual Studio so it should be a lot simpler.

Indeed. 

If you are using an IDE like Code::Blocks it should automatically find the SDK's compilers.

Greenhorn

Hi jc,

I also have VC 2010 Express installed and building amd64 binaries is very easy with that version.


  • Windows SDK v7.1 - install
  • Visual Studio 2010 Express - install (VC)
  • Visual Studio SP1 - install (should come via Windows Update, building amd64 binaries is broken now)
  • Fix-up for amd64 - install (VC-Compiler-KB2519277.exe should come via Windows Update)

Microsoft Windows SDK for Windows 7 and .NET Framework 4 (ISO)
(Choose the x64 ISO; you need a x64 OS !)
How to: Configure Visual C++ Projects to Target 64-Bit Platforms
(Choose the right version under the headline 2010)

That's all.


Regards
Greenhorn
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.