How to set a debugger flag on C build? - c++

I'am following a tutorial on making a game in C/C++. The building part takes place with just a .bat file. I'll show it.
#echo off
mkdir ..\build
pushd ..\build
cl -zi s:\games\game1\code\win32_game1.cpp user32.lib
popd
The flag -zi is used for getting the debugger output/information. The only problem is that when I run this script in the command line I get the following error:
Ignoring unknown option "-zi"
Can somebody tells me why -zi isn't working or what I can use instead? I'm using Visual Studio 2017.

Related

How do I link external libraries to msvc cl compiler

today I was trying to link my external SDL2 library to my project to compile with cl.exe, but my program cannot find SDL2.lib and SDL2main.lib and while I trying to include any files, compiler cannot see them. Here is my bat file:
#echo off
if not defined DevEnvDir (
call vcvarsall x64
)
REM call vcvarsall x64
set LIB_VCPKG="F:\Env\vcpkg\installed\x64-windows\lib"
set MLIB_VCPKG="F:\Env\vcpkg\installed\x64-windows\lib\manual-link"
set INC_VCPKG="F:\Env\vcpkg\installed\x64-windows\include"
set CommonCompileFlags=-MD -nologo -fp:fast -EHa -Od -WX- -W4 -Oi -GR- -Gm- -GS -wd4100 -FC -Z7 -I %INC_VCPKG%
set CommonLinkFlags=/SUBSYSTEM:CONSOLE /LIBPATH:%LIB_VCPKG% /VERBOSE:LIB
if not exist ..\build mkdir ..\build
pushd ..\build
cl ..\code\main.cpp SDL2.lib SDL2main.lib %CommonCompileFlags% /link %CommonLinkFlags%
popd
What should I do to resolve this problem?

How do I compile fips capable openssl on Windows x64?

I'm currently using the following steps but I'm having trouble compiling:
Add 64bit/32bit NASM to path: C:\Program Files\NASM for 64 bit
//On 32 bit simply switch to x86 native tool
Open native command prompt for VS2015 x64
or run "C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\bin\amd64\vcvars64.bat"
== Environment variables that need to be set ==
Set FPSDIR=C:\Dev\OpenSSL\x64\openssl-fips-ecp-2.0.16
Set PROCESSOR_ARCHITECTURE=AMD64
== Building Fips compliant module ==
cd openssl-fips-ecp-2.0.16
xcopy inc32\* include\* /O /X /E /H /K
=========
Open ms\do_fips.bat and remove "dll"
[Optional] add "debug" to same line
Open util\mk1mf.pl and add "libcmt.lib LIBCPMT.LIB libcmtd.lib LIBCPMTD.LIB" to EX_LIBS (Line 650 typically)
=========
ms\do_fips
mkdir lib
copy out32.dbg\* lib\*
mkdir bin
copy util\* bin\*
copy out32.dbg\fips_standalone_sha1.exe bin
== Building ==
cd openssl-1.0.2l
======
Open util\pl\VC-32.pl
remove "|| $fips " from line 48 and 133
[Optional]Open ms\do_win64a.bat and add "debug" to line 15 right before VC-WIN64A
======
perl Configure VC-WIN64A fips no-ec2m no-shared -DUNICODE -DOPENSSL_THREADS --with-fipsdir=C:\Dev\OpenSSL\x64\openssl-fips-ecp-2.0.16
ms\do_win64a
nmake -f ms\nt.mak clean
nmake -f ms\ntdll.mak clean
nmake -f ms\nt.mak
//On 32 bit be sure to do 32bit dir and
//Configure VC-WIN32
//ms\do_nasm (add debug here too)
Compiler is failing:
DOPENSSL_THREADS -DDSO_WIN32 -DOPENSSL_FIPS -DOPENSSL_NO_ERR -DUNICODE -DOPENSSL_THREADS -W3 -Gs0 -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -IC:\Dev\OpenSSL\x64\openssl-fips-ecp-2.0.16/include -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_SSL2 -DOPENSSL_NO_KRB5 -DOPENSSL_FIPS -DOPENSSL_NO_JPAKE -DOPENSSL_NO_WEAK_SSL_CIPHERS -DOPENSSL_NO_DYNAMIC_ENGINE /Zl /Zi /Fdtmp32/lib -c .\crypto\rand\rand_lib.c
rand_lib.c
.\crypto\rand\rand_lib.c(191): error C2143: syntax error: missing ')' before '*'
.\crypto\rand\rand_lib.c(191): error C2143: syntax error: missing '{' before '*'
.\crypto\rand\rand_lib.c(191): error C2059: syntax error: 'type'
.\crypto\rand\rand_lib.c(192): error C2059: syntax error: ')'
I looked at the code and it seems that it doesn't know what
DRBG_CTX
I searched and it should be included from FIPS directory, but it isn't, what is wrong with my build steps?
Found it, it seems by default the "include" directory is filled with 0kb files for some reason, I overwrited with the 32 bit include (inc32) directory's contents in the FIPS folder to the "include" one, and it seems to have solved the issue.
In case someone is wondering how to build it and pass the fips self-test.
Add 64bit/32bit NASM to path: C:\Program Files\NASM for 64 bit
//On 32 bit simply switch to x86 native tool and Set PROCESSOR_ARCHITECTURE=x86
Open native command prompt for VS2015 x64
or run "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
== Environment variables that need to be set ==
Set FPSDIR=C:\Dev\OpenSSL\x64\openssl-fips-ecp-2.0.16
Set PROCESSOR_ARCHITECTURE=AMD64
== Building Fips compliant module ==
cd openssl-fips-ecp-2.0.16
Open util\mk1mf.pl and add
$cflags.= " -DOPENSSL_FIPS_DEBUGGER";
after line 311
This will disable the fingerprint check for the module, whose purpose is to ensure that the source code hasn't been modified(but leave all other tests intact).
This is done because the fingerprint check appears to be broken for static libraries.
ms\do_fips
mkdir lib
copy out32dll\* lib\*
mkdir bin
copy util\* bin\*
copy out32dll\fips_standalone_sha1.exe bin
xcopy inc32\* include\* /O /X /E /H /K
== Building ==
cd openssl-1.0.2l
perl Configure VC-WIN64A fips no-ec2m no-shared -DUNICODE -DOPENSSL_FIPS_DEBUGGER -DOPENSSL_THREADS --with-fipsdir=C:\Dev\OpenSSL\openssl-fips-ecp-2.0.16
ms\do_win64a
nmake -f ms\nt.mak clean
nmake -f ms\ntdll.mak clean
nmake -f ms\nt.mak
//On 32 bit be sure to do 32bit dir and
//Configure VC-WIN32 ms\do_nasm

libffi with Visual Studio 2013

I need to compile the libffi library to use it in a Visual Studio 2013 project.
I am using libffi 3.0.13, downloaded from their original page
I have been struggling to make it work, following the instructions given in README, or trying to come up with something myself, but ended up failing pretty fast.
I tried:
using the Mingw environment to configure the libffi. But that is done for 'gcc' and 'make'. If I compile with gcc, it probably won't link with VS project correctly (right?). Besides, I don't have make (I would install it gladly, if gcc compilation would suffice)
using the ../configure CC="../msvcc.sh -m64" command as suggested in README, but my mingw does not know what cl is.
Tried providing the full path to cl.exe, but the compiler failed the configure tests. The log shows:
configure:3673: ../msvcc.sh conftest.c >&5
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe -MD -nologo -W3 conftest.c
conftest.c
LINK : fatal error LNK1104: cannot open file 'MSVCRT.lib'
Tried using the Visual Studio shell, but then the configure program is unknown
first, forgive my poor english! I solved this problem just now!
find your msvcc.sh
modify it, find this postion:
else
args="$md $args"
echo "$cl $args"
eval "\"$cl\" $args"
result=$?
fi
I add some flags:
else
args="$md $args"
echo "********"
args=" $args -ID:/soft/Microsoft\ Visual\ Studio\ 12.0/VC/include/ -link -LIBPATH:D:/soft/Microsoft\ Visual\ Studio\ 12.0/VC/lib/ -LIBPATH:C:/Program\ Files\ \(x86\)/Microsoft\ SDKs/Windows/v7.1A/Lib/"
echo "********"
echo "$cl $args"
eval "\"$cl\" $args"
result=$?
fi
change "D:/soft/Microsoft\ Visual\ Studio\ 12.0" these things to your path!
in cygwin: ./configure CC=E:/project/3rd_parth/libffi/libffi-3.0.13/msvcc.sh(also change the path)
done!
Hope it is not too late!

Error while building project when executing build step 'Make'

I've just installed Qt SDK 1.2.1 on my PC. I created a new project as a test:
File > New File or Project... > Other Project > Plain C++ Project
I chose these build settings:
Qt Creator generated this .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
and this main.cpp file:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
The build fails:
13:39:35: Running build steps for project test...
13:39:35: Starting: "C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe" clean
Could Not Find C:\Dev\Projects\Qt\test\debug\main.obj
del debug\main.obj
del debug\test.intermediate.manifest debug\test.exp debug\test.ilk vc*.pdb vc*.idb
Could Not Find C:\Dev\Projects\Qt\test\debug\test.intermediate.manifest
Could Not Find C:\Dev\Projects\Qt\test\vc*.pdb
Could Not Find C:\Dev\Projects\Qt\test\test.intermediate.manifest
Could Not Find C:\Dev\Projects\Qt\test\test.exp
Could Not Find C:\Dev\Projects\Qt\test\test.ilk
Could Not Find C:\Dev\Projects\Qt\test\vc*.pdb
c:\dev\qt\qtsdk\desktop\qt\4.8.1\msvc2008\bin\qmake.exe -spec ..\..\..\Qt\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008 CONFIG+=declarative_debug -o Makefile test.pro
C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe -f Makefile.Debug clean
C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe -f Makefile.Release clean
Could Not Find C:\Dev\Projects\Qt\test\release\main.obj
Could Not Find C:\Dev\Projects\Qt\test\release\test.intermediate.manifest
del release\main.obj
del release\test.intermediate.manifest release\test.exp
del ".\test.intermediate.manifest"
del test.exp
del test.ilk
del vc*.pdb
del vc*.idb
Could Not Find C:\Dev\Projects\Qt\test\vc*.idb
jom 1.0.8 - empower your cores
13:39:36: The process "C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe" exited normally.
13:39:36: Configuration unchanged, skipping qmake step.
13:39:36: Starting: "C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe"
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -I"..\..\..\Qt\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ #C:\DOCUME~1\Mitch!\LOCALS~1\Temp\main.obj.5936.16.jom
C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe -f Makefile.Debug
'cl' is not recognized as an internal or external command,
operable program or batch file.
jom: C:\Dev\Projects\Qt\test\Makefile.Debug [debug\main.obj] Error 1
jom 1.0.8 - empower your cores
jom: C:\Dev\Projects\Qt\test\Makefile [debug] Error 2
13:39:36: The process "C:\Dev\Qt\QtSDK\QtCreator\bin\jom.exe" exited with code 2.
Error while building project test (target: Desktop)
When executing build step 'Make'
I've tried running the Qt 4.8.1 for Desktop (MSVC 2008) batch script before starting Qt Creator and checking the Projects > Build Settings > Build Environment > Using System Environment > Clear System Environment without success.
My PATH variable after installing Qt SDK 1.2.1:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\jEdit;C:\Program Files\TortoiseSVN\bin;C:\Program Files\doxygen\bin;C:\Program Files\NVIDIA Corporation\Cg\bin;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\WINDOWS\system32\WindowsPowerShell\v1.0
My computer is running Windows XP Professional (Service Pack 2). The version of Qt Creator that ships with Qt SDK 1.2.1 is 2.4.1.
Looks like cl is either not installed on your system, or needs to be added to the PATH environment variable. Try to find the cl.exe binary somewhere in C:\Program Files\Microsoft Visual Studio [version]\ and add the directory that contains that binary to your PATH.

How do you compile OpenSSL for x64?

After following the instructions in INSTALL.W64 I have two problems:
The code is still written to the "out32" folder. I need to be able to link to both 32-bit and 64-bit versions of the library on my workstation, so I don't want the 64-bit versions to clobber the 32-bit libs.
The output is still 32-bit! This means that I get "unresolved external symbol" errors when trying to link to the libraries from an x64 app.
To compile the static libraries (both release and debug), this is what you need to do:
Install Perl - www.activestate.com
Run the "Visual Studio 2008 x64 Cross Tools Command Prompt" (Note: The regular command prompt WILL NOT WORK.)
Configure with
perl Configure VC-WIN64A no-shared no-idea
Run: ms\do_win64a
EDIT ms\nt.mak and change "32" to "64" in the output dirs:
# The output directory for everything intersting
OUT_D=out64.dbg
# The output directory for all the temporary muck
TMP_D=tmp64.dbg
# The output directory for the header files
INC_D=inc64
INCO_D=inc64\openssl
EDIT ms\nt.mak and remove bufferoverflowu.lib from EX_LIBS if you get an error about it.
Run: nmake -f ms\nt.mak
EDIT the ms\do_win64a file and ADD "debug" to all lines, except the "ml64" and the last two lines
Run: ms\do_win64a
Repeat steps 4 and 5
EDIT the ms\nt.mak file and ADD /Zi to the CFLAG list!
Run: nmake -f ms\nt.mak
I solved the problem this way, using the 1.0.1c source:
Add this block to util/pl/VC-32.pl, just before the $o='\\'; line.
if ($debug)
{
$ssl .= 'd';
$crypto .= 'd';
}
Add this block to util/pl/VC-32.pl, just before the if ($debug) line.
if ($FLAVOR =~ /WIN64/)
{
$out_def =~ s/32/64/;
$tmp_def =~ s/32/64/;
$inc_def =~ s/32/64/;
}
Then build all varieties:
setenv /x86 /release
perl Configure VC-WIN32 --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
nmake -f ms\ntdll.mak
setenv /x64 /release
perl Configure VC-WIN64A --prefix=build
ms\do_win64a.bat
nmake -f ms\ntdll.mak
setenv /x86 /debug
perl Configure debug-VC-WIN32 --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak
setenv /x64 /debug
perl Configure debug-VC-WIN64A --prefix=build
ms\do_win64a.bat
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak
Use Conan. It is very simple to install and use.
You can request the files ready for use. For example for Linux x64 or usage with Visual Studio 2012. Here a sample instruction:
conan install OpenSSL/1.0.2g#lasote/stable -s arch="x86_64" -s build_type="Debug" -s compiler="gcc" -s compiler.version="5.3" -s os="Linux" -o 386="False" -o no_asm="False" -o no_rsa="False" -o no_cast="False" -o no_hmac="False" -o no_sse2="False" -o no_zlib="False" ...
According to the official documentation:
"You may be surprised: the 64bit artefacts are indeed output in the out32* sub-directories and bear names ending *32.dll. Fact is the 64 bit compile target is so far an incremental change over the legacy 32bit windows target. Numerous compile flags are still labelled "32" although those do apply to both 32 and 64bit targets."
So the first answer is no longer necessary.
Instructions can be found here:
https://wiki.openssl.org/index.php/Compilation_and_Installation#W64
At the time of writing this how-to the most recent version of OpenSSL is 1.1.1a.
Environment:
Windows 10
MS Visual Studio 2017
Prerequisites:
Install ActivePerl - Community edition is fine
Install NASM
Make sure both Perl and NASM are in PATH environment variable.
Compiling x64:
Open x64 Native Tools Command Prompt
perl Configure VC-WIN64A --prefix=e:\projects\bin\OpenSSL\vc-win64a --openssldir=e:\projects\bin\OpenSSL\SSL
nmake
nmake test
nmake install
Step 4 is optional.
Compiling x86:
Open x86 Native Tools Command Prompt
perl Configure VC-WIN32 --prefix=e:\projects\bin\OpenSSL\vc-win32 --openssldir=e:\projects\bin\OpenSSL\SSL
nmake
nmake test
nmake install
Step 4 is optional.
If you're building in cygwin, you can use the following script, assume MSDEVPATH has already been set to your Visual Studio dir
echo "Building x64 OpenSSL"
# save the path of the x86 msdev
MSDEVPATH_x86=$MSDEVPATH
# and set a new var with x64 one
MSDEVPATH_x64=`cygpath -u $MSDEVPATH/bin/x86_amd64`
# now set vars with the several lib path for x64 in windows mode
LIBPATH_AMD64=`cygpath -w $MSDEVPATH_x86/lib/amd64`
LIBPATH_PLATFORM_x64=`cygpath -w $MSDEVPATH_x86/PlatformSDK/lib/x64`
# and set the LIB env var that link looks at
export LIB="$LIBPATH_AMD64;$LIBPATH_PLATFORM_x64"
# the new path for nmake to look for cl, x64 at the start to override any other msdev that was set previously
export PATH=$MSDEVPATH_x64:$PATH
./Configure VC-WIN64A zlib-dynamic --prefix=$OUT --with-zlib-include=zlib-$ZLIB_VERSION/include --with-zlib-lib=zlib-$ZLIB_VERSION/x64_lib
# do the deed
ms/do_win64a.bat
$MSDEVPATH_x86/bin/nmake -f ms/ntdll.mak ${1:-install}
The build instructions have changed since this question was originally asked. The new instructions can be found here. Note that you will need to have perl and NASM installed, and you will need to use the developer command prompt.
You can also use MSYS+mingw-w64:
1) download and extract msys to C:\msys
2) download and extract mingw-w64 to c:\mingw64
3) run msys postinstall script. When it asks for your mingw installation, point it to C:\mingw64\bin
4) Extract an openssl daily snapshot (1.0.0 release has a bug). In the source dir run
configure mingw64
make
make check
make install
5) openssl is installed to /local/