1

Currently I am trying to use the C standard library in my EDK2 project. As my Visual Studio 2019 did not automatically add the necessary include directories, I manually added the following folders to my include directories:

C:\edk2\MdePkg\Include\X64
C:\edk2\MdePkg\Include
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29812\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29812\atlmfc\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Auxiliary\VS\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\cppwinrt
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um

As this fixed my missing #include directives, the only thing left for me was to manually add the missing libraries to the linker arguments.

I did this as follows:

1.) After a quick Google search i found out, that I have to link my application against libucrt.lib, which i then tried to locate inside of my Windows 10 SDK by performing a simple search, which yielded me the following results:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64

As a result, I added this directory to my library directories inside Visual Studio 2019. Not to forget, I added libucrt.lib as well: Linker Libraries

My problem is, that after compiling my project, I still get an error from the linker: Linker error

I already tried out using different include directories, as well as different Windows SDK versions, but none seemed to solve my problem.

I am grateful for any kind of help, thank you.

Dalex
  • 61
  • 1
  • 5
  • 1
    I'm not totally sure what you are trying to do but UEFI is a firmware interface. You don't "manually link the C standard" to a UEFI application. In a EFI bootloader you simply don't have the OS API required to do system calls (interrupts) that the C standard library requires. When you link statically with the Windows provided libraries, you include all code up to the system call. That's where static linking is limited. You can't include interrupt code in a statically linked program no matter how hard you try. – user123 Mar 29 '21 at 03:20
  • Most of the standard library calls that you make in C have their own EDK2 versions. You can use these versions instead or simply implement the functions yourself which is often trivial. – user123 Mar 29 '21 at 03:28

1 Answers1

0

I settled on implementing the functions I needed from the stdlib myself, as @user123 proposed, in order to solve this problem and save me a lot of time.

Dalex
  • 61
  • 1
  • 5