How do you compile OpenSSL for x64? - c++

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/

Related

How to build the latest clang-tidy?

I've tried to build clang-tidy from sources but it complains about an undefined CMake command:
CMake Error at clang-apply-replacements/CMakeLists.txt:5 (add_clang_library):
Unknown CMake command "add_clang_library".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.9)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
How can I build clang-tidy or, alternatively, how can I install the latest version on macOS?
Up-to-date steps:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
make install clang-tidy
Reference, ninja, and other details: my own blog post.
EDIT: this answer is out of date — the LLVM project has moved to a single git repository at https://github.com/llvm/llvm-project. See answers below for updated instructions.
clang-tidy is intended to be built inside a checkout of llvm/clang, and depends on CMake macros from the llvm project. You should check out the llvm repo, then the clang repo inside llvm/tools/clang, then the clang-tools-extra repo inside llvm/tools/clang/tools/extra. Then you can run CMake on the top-level directory, and make clang-tidy should work.
If you're not interested in building it yourself, it looks like the Homebrew formula for LLVM also includes the extra tools: https://github.com/Homebrew/homebrew-core/blob/382d3defb5bc48ce2dccd17261be70c4ada9a124/Formula/llvm.rb#L181
I had same problem as Per Mildner. Got is solved with slightly modified code YvesgereY posted (I don't have enough reputation to post a comment to that answer, hence a new answer instead).
In short, I added -G "Unix Makefiles" to cmake. Without this option, no makefile will be generated. Also, I used -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;". It didn't work when just clang-tools-extra was specified.
Here is the whole snippet:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;" ../llvm
make -j8 install-clang-tidy
#jtbandes: Thank you for the information.
I'd like to share these explicit steps for us noobs:
1. Download the released sources from LLVM Download Page
LLVM source code -> Links to the file llvm-6.0.0.src.tar.xz
Clang source code -> Links to the file cfe-6.0.0.src.tar.xz
clang-tools-extra -> Links to the file clang-tools-extra-6.0.0.src.tar.xz
2. Detar each of these into the proper directory:
$ tar -zxvf <download_dir_path>/llvm-6.0.1.src.tar.xz
$ cd llvm-6.0.1.src/tools
$ tar -zxcf <download_dir_path>/cfe-6.0.1.src.tar.xz
$ cd llvm-6.0.1.src/tools/cfe-6.0.1.src/tools
$ tar -zxvf <download_dir_path>/clang-tools-extra-6.0.1.src.tar.xz
Results in a directory llvm-6.0.1.src/tools/cfe-6.0.1.src/tools/clang-tools-extra-6.0.1.src/clang-tidy; Which is incorrect. The lang-tools-extra-6.0.1.src needs to be renamed to extra (as mentioned by #jtbandes).
3. So rename it or provide a symbolic link:
$ cd llvm-6.0.1.src/tools/cfe-6.0.1.src/tools
$ mv clang-tools-extra-6.0.1.src extra
or
$ ln -s clang-tools-extra-6.0.1.src extra
The path llvm-6.0.1.src/tools/cfe-6.0.1.src/tools/extra/clang-tidy should now be valid
4. Build it:
$ cd llvm-6.0.1.src
$ mkdir build
$ cd build
$ cmake ..
$ make
Everything should make without errors or warnings.
5. Build Output:
The build output can be found in llvm-6.0.1.src/build/bin.
For everyone who are looking for latest (LLVM 11) Windows build instructions (ensure CMake, Visual Studio 2019 and git are installed and set in PATH):
git clone --config core.autocrlf=false https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -Thost=x64 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
cmake --build . --target clang-tidy --config RelWithDebInfo --parallel
cmake --build . --target clang-query --config RelWithDebInfo --parallel
This worked for me:
mkdir build
files="
llvm-12.0.1.src.tar.xz
clang-12.0.1.src.tar.xz
clang-tools-extra-12.0.1.src.tar.xz
"
for f in $files; do
echo "Untar $f"
tar xf $f
done
mv llvm-12.0.1.src llvm
mv clang-12.0.1.src llvm/tools/clang
mv clang-tools-extra-12.0.1.src llvm/tools/clang/tools/extra
cd build
cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/llvm \
-DCLANG_BUILD_TOOLS=ON \
../llvm
make -j16 install
As of LLVM 14.0.0, sparse checkouts do no longer work (at least temporarily) and the top-level directory contains no CMakeLists.txt. I believe the tree layout has changed after LLVM 13.0.1. In consequence, none of the approaches here worked without quite some modification.
Here is how you can build version 15.0.0git (the most recent at the time of this writing). See related issue: https://github.com/llvm/llvm-project/issues/53281.
First, get the compressed code or clone with git (slower)
$ wget "https://github.com/llvm/llvm-project/archive/refs/heads/main.zip" -O llvm.zip
$ unzip llvm.zip
As usual, create a build directory and run cmake in the llvm directory.
$ mkdir /build
$ cd /build
$ cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr/local/llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
/llvm-project-main/llvm
Navigate downwards in the generated files and only build clang-tidy.
$ cd /build/tools/clang/tools/extra/clang-tidy
$ make install
Cmake will install to /usr/local/llvm. Also, if you want to check out a specific version, use tags in the first step like this:
$ wget "https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-14.0.0.zip"
Note that you need to supply the matching builtin headers for running clang-tidy, which are located in GitHub under llvm-project/clang/lib/Headers and can by pointed to with -extra-arg=-I/path/to/builtin/headers.

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!

wxWidget 2.8.12 not working in Codeblocks

I'm learning to use wxWidget 2.8.12 with Codeblocks 12.11. I have followed the instructions on this site to install wxWidgets and Codeblocks:
http://wiki.codeblocks.org/index.php?title=WxWindowsQuickRef
When I try to create the project and run the demo app I get the error:
fatal error: wx/setup.h: No such file or directory
The following picture will show this better:
I have followed the instructions, but still I get the error...what seems to be the problem? :(
Thnx for any help
P.S.
Here is an overview what I have done:
1) I downloaded Codeblocks including MinGW (codeblocks-12.11mingw-setup.exe)
http://www.codeblocks.org/downloads/26#windows and I have installed them using the .exe file
2) I have edited my User PATH environment variable to according to the reference page I have used
3) I have downloaded wxWidgets installer from this link and installed it:
http://sourceforge.net/projects/wxwindows/files/2.8.12/wxMSW-2.8.12-Setup.exe/download?use_mirror=garr
4) I have entered the directory C:\<wxWidgets root>\build\msw and inputted the following command in command prompt:
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport
After letting wxWidgets build and trying to run my demo app I get the error I mentioned in Codeblocks :(
NOTICE FUTURE READERS: Install wxWidgets to a directory without whitespace in the path name! Otherwise this will cause trouble
Please have a look at the Below Link which i have put.It will be very useful.I have also installed wxWidget 2.8.12 with Codeblocks 12.11 using This Link.
Setting up wxWidgets(2.9.4) with Code::Blocks(12.11) in Windows
Type These below steps in Command Prompt after you finish installing the wxWidgets2.8.12 and CODEBLOCKS 12.11.
gcc -v
mingw32-make -v
cd /D C:\wxWidgets-2.8.12\build\msw
mingw32-make -f makefile.gcc clean
mingw32-make -f makefile.gcc BUILD=debug SHARED=0 MONOLITHIC=1 UNICODE=1
mingw32-make -f makefile.gcc BUILD=release SHARED=0 MONOLITHIC=1 UNICODE=1
If the problem still persists after doing all the above steps then You're missing an important compiler search path in your build options.
Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard.
If re-running the wizard isn't an option, then open your project's build options and add "$(#wx.lib)\gcc_dll\mswu" (assuming a monolithic Unicode DLL build) to the compiler search paths.

Unresolved symbols with boost_asio/example/ssl/client.cpp [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
boost::asio ssl linking error
I am having issues with undefined symbols. My boost installation is fine as I have used it for other projects. I understand that I need OpenSSL installed, So installed it in the following way.
I then ran the following commands with VS2010 command prompt with the extracted OpenSSL source (most recent from openssl site) as the working directory.
perl Configure VC-WIN64A no-shared no-idea // I don't trust this.
ms\do_win64a
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
The source file is just the boost example. http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/example/ssl/client.cpp
My VS2010 project is setup as follows.
C/C++ > General > Addition Include Directories
E:\libraries\boost_1_49_0 //as used in past projects
E:\usr\local\ssl\include //just installed
Linker > General > Addition Library Directories
E:\libraries\boost_1_49_0\stage\lib
E:\usr\local\ssl\lib
Linker > Input > Addition Directories
libeay32.lib
I thought that it might must have been boost tripping out. So I tried an SSL crypto example and that had undefined symbols.
Errors in a text file
OS is Windows 7 64Bit
I was trying to build a 32bit program with the 64 bit libs.
I changed the following from above to build the 64 bit version
perl Configure VC-WIN64A no-asm --prefix=\Dir\for\64\bit\ssl -DUNICODE -D_UNICODE
ms\do_win64a.bat
then nmake as normal

Compiling 64 bit qt (from source) using cmake on windows

I failed to compile qt shared library(64 bit) on windows using various versions of cmake. I think am making some mistakes in selecting cmake options. Can any one point me to some tutorials or tell the steps to be followed. Thanks in advance. (I can't use visual studio for this.)
This post worked for me :
#ECHO OFF
rmdir /Q /S C:\Qt\qt-git-build
mkdir C:\Qt\qt-git-build
cd C:\Qt\qt-git-build
..\qt-git\configure -opensource -mp -qt-zlib
nmake
nmake qdoc3
editbin /STACK:0x200000 bin\qdoc3.exe
nmake docs
nmake install
nmake clean
cd ..