c++64-bitmsvc12

error compiling openCTM in x64


I'm trying to compile openCTM using VC12 in x64. OpenCTM is downloaded from: openctm-1.0.3-src.zip

In order to compile, I run: nmake /f Makefile.msvc

To setup the environment I use the following bat file:

@rem Setting environment for using Microsoft Visual Studio x86/x64 tools.
@echo off

@if "%1"=="vc11_x86" goto set_vc11_x86
@if "%1"=="vc11_x64" goto set_vc11_x64
@if "%1"=="vc12_x64" goto set_vc12_x64
@if "%1"=="" goto error

:set_vc11_x86
@echo Setting environment for using Microsoft Visual Studio 2011 x86 tools.

set INCLUDE=^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include;^
C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;

set LIB=^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\;^
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\;^
C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x86\;


set PATH=^
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
%SystemRoot%\system32;^
%SystemRoot%;^
%SystemRoot%\System32\Wbem;^
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
C:\MinGW\bin\;^
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\;^
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\;

goto test_bin_locations

:set_vc11_x64
@echo Setting environment for using Microsoft Visual Studio 2011 x64 tools.

set INCLUDE=^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include;^
C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;

set LIB=^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\;^
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\;^
C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x86\;

set PATH=^
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
%SystemRoot%\system32;^
%SystemRoot%;^
%SystemRoot%\System32\Wbem;^
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
C:\MinGW\bin\;^
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\;^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\;^
C:\Program Files (x86)\Windows Kits\8.1\bin\x64;

goto test_bin_locations

:set_vc12_x64
@echo Setting environment for using Microsoft Visual Studio 2012 x64 tools.

set INCLUDE=^
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include;^
C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;

set LIB=^
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64\;^
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\;^
C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x86\;

set PATH=^
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
%SystemRoot%\system32;^
%SystemRoot%;^
%SystemRoot%\System32\Wbem;^
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
C:\MinGW\bin\;^
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\;^
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\;^
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\;^
C:\Program Files (x86)\Windows Kits\8.1\bin\x64;

goto test_bin_locations

:test_bin_locations
@echo on
where nmake
where cl.exe
where link.exe
@echo off
goto:eof

:error
@echo Usage: setenv.bat [vc11_x86^|vc11_x64^|vc12_x64]

goto:eof

Compiling generates the openctm.dll when I use the vc11_x86 environment.

But it fails when using the vc11_x64 or vc12_x64 environment.

vc12_x64 main error:

        link /MACHINE:X64 /nologo /out:openctm.dll /dll /implib:openctm.lib /def
:openctm-msvc.def openctm.obj  stream.obj  compressRAW.obj  compressMG1.obj  com
pressMG2.obj Alloc.obj  LzFind.obj  LzmaDec.obj  LzmaEnc.obj  LzmaLib.obj openct
m.res
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'

vc11_x86 main error:

Alloc.obj : error LNK2001: unresolved external symbol free
openctm.obj : error LNK2019: unresolved external symbol free referenced in funct
ion ctmFreeContext
stream.obj : error LNK2001: unresolved external symbol free
compressMG1.obj : error LNK2001: unresolved external symbol free
compressMG2.obj : error LNK2001: unresolved external symbol free
Alloc.obj : error LNK2001: unresolved external symbol malloc
openctm.obj : error LNK2019: unresolved external symbol malloc referenced in fun
ction ctmNewContext

Please point me in the right direction on how to solve this issue.


Solution

  • ok, I've found the issues:

    1. I installed Microsoft Visual Studio Express 2013 for Windows. Installing Microsoft Visual Studio Express 2013 for Desktop solved the vc12_x64 issue

    2. There was an reference to x86 libraries in the setenv.bat file. The correct file is:

    @rem Setting environment for using Microsoft Visual Studio x86/x64 tools.
    @echo off
    
    @if "%1"=="vc11_x86" goto set_vc11_x86
    @if "%1"=="vc11_x64" goto set_vc11_x64
    @if "%1"=="vc12_x64" goto set_vc12_x64
    @if "%1"=="" goto error
    
    :set_vc11_x86
    @echo Setting environment for using Microsoft Visual Studio 2011 x86 tools.
    
    set INCLUDE=^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;
    
    set LIB=^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\;^
    C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\;^
    C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x86\;
    
    
    set PATH=^
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
    %SystemRoot%\system32;^
    %SystemRoot%;^
    %SystemRoot%\System32\Wbem;^
    %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
    C:\MinGW\bin\;^
    C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
    C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
    C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\;^
    C:\Program Files (x86)\Windows Kits\8.1\bin\x86\;
    
    goto test_bin_locations
    
    :set_vc11_x64
    @echo Setting environment for using Microsoft Visual Studio 2011 x64 tools.
    
    set INCLUDE=^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;
    
    set LIB=^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\;^
    C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\;^
    C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x64\;
    
    set PATH=^
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
    %SystemRoot%\system32;^
    %SystemRoot%;^
    %SystemRoot%\System32\Wbem;^
    %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
    C:\MinGW\bin\;^
    C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
    C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
    C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\;^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\;^
    C:\Program Files (x86)\Windows Kits\8.1\bin\x64;
    
    goto test_bin_locations
    
    :set_vc12_x64
    @echo Setting environment for using Microsoft Visual Studio 2012 x64 tools.
    
    set INCLUDE=^
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\um;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\shared;^
    C:\Program Files (x86)\Windows Kits\8.1\Include\WinRT;
    
    set LIB=^
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64\;^
    C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\;^
    C:\Program Files (x86)\Windows Kits\8.0\Lib\Win8\um\x64\;
    
    set PATH=^
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;^
    %SystemRoot%\system32;^
    %SystemRoot%;^
    %SystemRoot%\System32\Wbem;^
    %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;^
    C:\MinGW\bin\;^
    C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;^
    C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;^
    C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\;^
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\;^
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\;^
    C:\Program Files (x86)\Windows Kits\8.1\bin\x64;^
    C:\Program Files (x86)\MSBuild\12.0\Bin\amd64;
    
    goto test_bin_locations
    
    :test_bin_locations
    @echo on
    where nmake
    where cl.exe
    where link.exe
    @echo off
    goto:eof
    
    :error
    @echo Usage: setenv.bat [vc11_x86^|vc11_x64^|vc12_x64]
    
    goto:eof