Can't build gdal in x64 - c++

I am trying to build GDAL (1.9.2) in x64.
In the instructions, I see:
# Uncomment the following if you are building for 64-bit windows
# (x64). You'll need to have PATH, INCLUDE and LIB set up for 64-bit
# compiles.
!IF "$(PLATFORM)" == "x64"
WIN64=YES
!ENDIF
And then, lower,
# Under win64, symbols for function names lack the underscore prefix
# present on win32. Also the STDCALL calling convention is not used.
!IFDEF WIN64
!UNDEF STDCALL
!ELSE
SYM_PREFIX=_
!ENDIF
Can't find a PATH, INCLUDE and LIB specific for x64, or anything else that I should do...
I can build in Win32.
In x64, I get linker errors:
LINK : error LNK2001: unresolved external symbol _OGRFeatureStylePuller
LINK : error LNK2001: unresolved external symbol _OSRValidate
...
gdal19.dll : fatal error LNK1120: 74 unresolved externals
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\BIN\link.EXE"' : return code '0x460'
I put (to build in Win32)
!IFNDEF PLATFORM
PLATFORM=WIN32
!ENDIF
Modified to
!IFNDEF PLATFORM
PLATFORM=x64
!ENDIF
(to build in x64) - And it worked. But only if I build from inside Visual Studio.
I would like to be able to use a bat file (and build alll platform/configurations)
The above - while it builds in VS, it will not build from command line
(with commands:
start /b /wait nmake -f makefile.vc clean
start /b /wait nmake.exe /f makefile.vc PLATFORM=x64
start /b /wait nmake.exe /f makefile.vc devinstall PLATFORM=x64
The exact same thing builds in Win32...
I can't figure out what is wrong...

I managed to build x64 version of GDAL under Visual Studio 2012 using steps from http://dominoc925.blogspot.ru/2013/03/build-64-bit-gdal-for-windows.html:
Download gdal-1.9.2.tar.gz (or other version of sources) from http://download.osgeo.org/gdal/
Unpack to some directory, e.g. C:\tmp\gdal-1.9.2\
If you tried to build GDAL previously (e.g. x86), make sure that the build directory (C:\warmerda\bld\) and the source directory are clean from previous build attempt. If unsure, try to unpack sources in a new directory.
Start VS2012 x64 Native Tools Command Prompt:
Start -> All Programs -> Microsoft Visual Studio 2012 -> Visual Studio Tools -> Open VS2012 x64 Native Tools Command Prompt
Or run
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" amd64).
Change directory to the directory with unpacked GDAL sources:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>cd /D C:\tmp\gdal-1.9.2
D:\trn4\gdal-1.9.2>
Build GDAL with development files:
nmake /f makefile.vc MSVC_VER=1700 WIN64=YES
nmake /f makefile.vc MSVC_VER=1700 WIN64=YES install
nmake /f makefile.vc MSVC_VER=1700 WIN64=YES devinstall
You can get your MSVC_VER number from here. GDAL will be built and installed to C:\warmerda\bld\.

To build with nmake command line I had to run the command from a command shell that has the appropriate variables set to build for 64 bits.
This is what I did to set up the 64 bits building environment:
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64

You should first somehow make clear to readers of this thread that over the 6 edits you've done yet, the focus of your question changed more than once, as one can see from the revision history
Anyway:
Now it's just a batch vs ide build job issue; try exporting the makefile from VS
EXPORTING! NOT just opening the package orginal makefile.vc in an editor window!
, save it under a name different from the package's "makefile.vc" and use that in your batch.

"I can build in Win32."
Have you had built for Win32 BEFORE your Win64 built attempt?
If so, pls attend
http://trac.osgeo.org/gdal/ticket/4636, bottom of the reply list:
Just to note for anyone else having the issue.. I'll try to look more
into this when I can.. but in the meantime, a clean build is not
really doing a "clean" so make sure you manually delete your files if
you do a 32 bit build before your 64bit build.
You could also try to simply extract the source again at a different directory, in order to have a clean tree and try to build there for Win64.

Related

Setting up Curl for Visual Studio 2017: NMAKE: fatal error U1073: don't know how to make '..\src\tool_hugehelp.c'

I'm currently trying to build curl for VS2017, when setting things up with x86 Native Tools Command Prompt, I run the command:
nmake /f Makefile.vc mode=static vc=15 debug=yes
When it gets to the part "Copying libs" it gives me the error:
NMAKE: fatal error U1073: don't know how to make '..\src\tool_hugehelp.c'
As well as another error below:
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
Does anyone know why these errors would be occurring? Or how to resolve them?
If the first answer did not clear things up(if though it is the right.)
Download the lib curl from Github.
Steps for building x64 Debug:
Open x64 Native Tools Command Prompt VS 2019
cd into the repo.
open the repo in file explorer and double click buildconf.bat
file.
cd into \buildtools in x64 Native Tools Command Prompt VS
2019
Type, set RTLIBCFG=static, Press enter.
6.Type, nmake /f Makefile.vc mode=static vc=16 debug=yes
For Release
Type, nmake /f Makefile.vc mode=static vc=16 debug=no
after download and unzip curl files , u find in Curl directory buildconf.bat , run them and u get tool_hugehelp.c for nmake

How can I run cl using x64?

I had the same problem as here fatal error C1034: windows.h: no include path set
I typed vcvars32.bat and that solved my problem but I want to link some 64-bit .lib files and when I do:
cl main.cpp xxxlib.lib
I get:
warning LNK4272: library machine type 'x64' conflict with target machine type 'x86'
Is it because I use the vcvars32.bat is 32 bits? Where can I find the 64 bit version?
Thanks
In order to make sure you have the proper environment variables set, the simplest way is to launch the respective command shell in the start menu.
For 64bit, this would be Visual Studio x64 Win64 Command Prompt (2010), then cl.exe is automatically correct. If you show the properties of this entry in the start menu, you'll also find more infos:
Start in: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\"
Target : %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64
From this, you see that the working directory is set, and vcvarsall.bat is called with the amd64 parameter. This is probably what you missed.

Build OpenSSL in Visual Studio 2013

How to build OpenSSL in Visual Studio 2013?
I try to compile in this lesson, but there is an error:
Assembling: tmp32\x86_64cpuid.asm
tmp32\x86_64cpuid.asm(1) : error A2088:END directive required at end of file
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\
I compiled under x64. What could be the problem? Thank you in advance.
I wrote a note to build OpenSSL here (Unix and Windows).
Make sure you use the original OpenSSL source (do not re-use the compiled source code).
Open the Visual Studio x64 Win64 Command Prompt (2010) (in the Start menu)
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" amd64
perl Configure VC-WIN64A --prefix=C:\openssl_x64 no-asm no-shared enable-tlsext enable-static-engine
ms\do_win64a
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install
I remember encountering also the same error building OpenSSL 1.0.2d as a static library. A solution that worked for me is the following :
In a new command line window build OpenSSL and install it into C:\build\bin\openssl-1.0.2d-x64 directory:
cd C:\build\src\openssl-1.0.2d-x64
set PATH=%PATH%;C:\nasm
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64
perl Configure VC-WIN64A --prefix=C:\build\bin\openssl-1.0.2d-x64 enable-static-engine
ms\do_win64a
nmake /f ms\nt.mak
nmake /f ms\nt.mak test
nmake /f ms\nt.mak install
Resulting build is located in C:\build\bin\openssl-1.0.2d-x64 directory.
Hope that helps !
Take this answer updated for visual studio 2015
1 - Make sure to use the 1.0.2h openssl source.
2 - Make sure that you install (Old) nasm (NOT THE LATEST): use version 2.11 [1]:http://www.nasm.us/pub/nasm/releasebuilds/2.11/ from 2013 and put it on your path.
3 - Open any normal Command Prompt (cmd) - administrator is preferred - and execute these commands in the root directory of the downloaded source.
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" amd64
perl Configure VC-WIN64A --prefix=C:\openssl_x64 no-asm no-shared enable-tlsext enable-static-engine
ms\do_win64a
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install
Update for Visual Studio 2017:
1) I used the 1.0.2h openssl source. I have not tried other versions.
2) Have perl installed and in your PATH.
3) Install NASM and add it to your PATH (e.g. to C:\NASM and/or edit the PATH setup below). The latest version (2.13.1) worked fine for me.
4) Check and, if needed, edit the path to vcvarsall.bat used below.
5) (optional) Edit the install folder in the command bellow (set via --prefix).
6) Open Command Prompt in the root directory of the downloaded source, (edit and) execute the following commands:
set PATH=%PATH%;C:\nasm
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat"" amd64
perl Configure VC-WIN64A --prefix=C:\openssl_x64 no-asm no-shared enable-tlsext enable-static-engine
ms\do_win64a
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install
7) (Optional) In case you have multiple versions of VS installed, you might want to verify that the correct version of nmake was executed (14.10.* and not e.g. 14.0* or 12.*)

Qt Windows x64 build succeeds in IDE but not on the command line

I have a Qt project I'm trying to automate. On Windows I build for both 32-bit and 64-bit platforms. I am using Visual Studio 2013. I have the following Qt Kits installed: Desktop Qt 5.5.1 MSVC2013 32bit, and Desktop Qt 5.5.1 MSVC2013 64bit. All four versions (32-bit debug and release, and 64-bit debug and release) can be built and run without any trouble from the IDE. Unfortunately, building from the command line fails with this error:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
My command-line system, intended for eventual use in a batch file, and run in my project directory, is:
pushd Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
call vcvars32.bat
popd
md build64
cd build64
G:\Qt\5.5\msvc2013_64\bin\qmake.exe -spec win32-msvc2013 -o Makefile ..\Maps.pro
G:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Release
I use this command in a command window (after setting up the path using vcvars32 so that the Visual Studio tools like nmake, rc and link can be found) and get the error. Note that the command-line method works perfectly for my 32-bit build.
The qmake command line I use is copied from the one recorded in a comment in the Makefile created by the IDE, which claims it is the command used to create that makefile. I know that the "-spec win32-msvc2013" option looks strange, but it works when the IDE uses it.
The jom command line I use is the one used by the IDE, as logged by the Compile Output window.
The only thing I can think of is that Qt sets up some 'magic' environmental variables which I don't know about.
[Yes, I have googled very extensively and looked at other questions and answers here, and can't find anything that fits this case.]
This code
pushd Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
vcvars32.bat
popd
sets up environment for building for 32-bit architecture. Run vcvars32.bat from different directory (I think it should have amd64 in its name, don't have Windows computer at the moment so can't say the exact directory name, but you'll figure out).
Or do
pushd "<DRIVE>:\Program Files (x86)\Microsoft Visual Studio <Version>\Common7\Tools"
vsvars32 x64
popd
Update for VS2017:
For 64-bit architecture use this command:
"<DRIVE>:\Program Files (x86)\Microsoft Visual Studio\2017\<Version>\VC\Auxiliary\Build\vcvars64.bat"
and for 32 bits:
"<DRIVE>:\Program Files (x86)\Microsoft Visual Studio\2017\<Version>\VC\Auxiliary\Build\vcvars32.bat"

How to build a QT-project in visual studio from command line

I am trying to automate the build process for one of my QT-project. I used the following command in my batch file for non-QT projects
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "myproject.sln" /build "Debug|x64" /projectconfig Debug
but it is not working for my QT project. Am I missing something?
Here is an example on how to do that (command by command):
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cd <my_project_directory>
qmake
nmake
The first command sets up the environment for using Visual Studio tools.
Second command changes the current directory to one where your Qt project file is (you have to have one).
Third command runs Qt's qmake.exe utility to generate make files.
And finally nmake will build your project.
However, if you don't use Qt project files and have only VisualStudio solution, you can use MSBuild utility, like:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
MSBuild your_solution.sln /p:Configuration=Debug
You can also set additional environment variables, such as QTDIR if it does not find your Qt installation.
If somebody finds this question looking for an answer on how to automate the build process of a QT project, and wants to do it using a BATCH file as the original question states, here is the BATCH script that I used to automate my building process:
#echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
cd %path_to_your_repo%
nmake /f Makefile.Release clean && qmake.exe %path_to_your_.pro% -spec win32-msvc "CONFIG+=qtquickcompiler"
nmake qmake_all
nmake -f Makefile.Release
It is important to call the vcvarsall.bat the first thing, as this will set the environment for all visual studio tools. Also make sure to launch it with call, if you just start the batch file as in #vahancho's answer it will stop your script after executing vcvarsall.bat.
The clean step is not necessary but it is a good practice to use it before building.
It is important to select the -spec and CONFIG (if any) during the qmake step, as this will allow you to select the compiler and required configuration if you are using some extra QT configuration.