ionescu007 / VisualUefi

A project for allowing EDK-II Development with Visual Studio
486 stars 122 forks source link

BaseCryptLib #4

Closed Bowser1991 closed 8 years ago

Bowser1991 commented 8 years ago

Hi, I'm having trouble creating the BaseCryptLib. I always get an LNK2001 error in my application project. But the Library compiles without errors

BaseCryptLib.lib(CryptSha256.obj) : error LNK2001: "SHA256_Init" I don't know what I'm doing wrong

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptMd4.c" />
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptMd4Null.c" />
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptMd5.c" />
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptSha1.c" />
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptSha256.c" />
    <ClCompile Include="..\..\edk2\CryptoPkg\Library\BaseCryptLib\Hash\CryptSha512.c" />
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{F2F48219-245E-4740-A859-9B7AC502DCBD}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>BaseCryptLib</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(SolutionDir)\edk2.props" />
  <PropertyGroup Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>..\..\edk2\MdePkg\Include\;..\..\edk2\MdePkg\Include\X64;$(IncludePath);..\. .\edk2\CryptoPkg\Library;..\..\edk2\CryptoPkg\Include;..\..\edk2\CryptoPkg\Library\BaseCryptLibRuntimeCryptProtocol;..\..\edk2\CryptoPkg\Include\openssl;..\..\edk2\CryptoPkg\Library\OpensslLib\openssl-1.0.2e\lib</IncludePath>
    <IntDir>$(SolutionDir)$(Platform)\$(Configuration)\obj\</IntDir>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LibraryWPath>$(WindowsSDK_MetadataPath);..\..\edk-ii\$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryWPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <BufferSecurityCheck>false</BufferSecurityCheck>
      <ForcedIncludeFiles>..\..\..\EDK-II\BaseLib\vshacks.h</ForcedIncludeFiles>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
  </ImportGroup>
</Project>

This is my Visual Studio Projekt File. I hope you can help me

Kind regards Daniel

ionescu007 commented 8 years ago

Hi Daniel,

First, I recommend you move to using the new ".props"-style project files, as these are much simpler to deal with. Take a look at any of the .vcxproj files that are now used in the project, such as UefiLib.vcxproj.

Second, you probably don't want: "ClCompile Include="CryptMd4Null.c" as this will compile an "empty" implementation of crypto functions.

Then, make sure you add BaseCryptLib.lib to the section of your .props file in \samples, or the one your .vcxproj is using.

If this doesn't help, I will take a look in a week or so, as I am currently away.

Bowser1991 commented 8 years ago

Hi, I tried it again with your suggestions but it is still not working. I think it has to do with the openssl library from which the function SHA256_Update comes from. I compiled the Library for Windows and linked to the ssleay32.lib & libeay32.lib librarys. But there are more errors like:

1>libeay32.lib(asn1_lib.obj) : error LNK2001: unresolved external reference "memcpy". 1>libeay32.lib(obj_lib.obj) : error LNK2001: unresolved external reference "memcpy". 1>libeay32.lib(buf_str.obj) : error LNK2001: unresolved external reference "memcpy".

Kind regards Daniel

ionescu007 commented 8 years ago

Looks like you're missing CryptoPkg\Library\IntrinsicLib as well.

ionescu007 commented 8 years ago

You may also want to look at http://git.infradead.org/users/dwmw2/edk2.git which is from Intel's attempt to get the OpenSSL support for UEFI directly into upstream.

ionescu007 commented 8 years ago

Looka like OpenSSL 1.1.0 will build natively with two fixes from the openssl.git from that git repository, plus this EDK-II fork (which should be merged back to EDK-II shortly).I will make VisualUefi track that project and create project files for building OpenSSL. If it works out, I'll update the project.

ionescu007 commented 8 years ago

With a few changes to the openssl repo, OpensslLib now builds. I will work some more on this tomorrow and contacted Intel/David to get the fixes/clarification upstream as well. Tomorrow I will try to now get BaseCryptoLib building.

ionescu007 commented 8 years ago

Worked with Intel to get openssl into better shape. There are two remaining issues, but I am able to locally build BaseCryptLib, OpensslLib together with Cryptest, and exercise the code paths.

Bowser1991 commented 8 years ago

Hi, sorry I was away this weekend thats why i couldn't answer your comments. Yes I saw that i was missing the IntrinsicLib and build that one succussfully but had still trouble compiling the OpenSSL lib.

Thank you for your work on the BaseCryptLib i will test it tomorrow and give you some feedback.

Kind regards Daniel

ionescu007 commented 8 years ago

Hi Daniel,

With the latest work from Intel + two changes to the project file, you should now be able to build all the libraries required. For an example of something using BaseCryptLib, please see Cryptest. Please let me know by filing a new issue if you're experiencing issues building any of these components.

Thanks for your patience, Alex