MSVC Manually Linking stdlib - c

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:
My problem is, that after compiling my project, I still get an error from the linker:
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.

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.

Related

Project won't build because it can't load an assembly

Reports error on loading dll
I'm using Visual Studio 2019 Enterprise version 16.2.0
I have a dll library called RDLFunctions.dll to use in another WinForms application. Both projects are in the same solution that has worked for many years until I upgraded to Visual Studio 2019 and I can't go back. The WinForm app has about 50 reports and references the dll, but on project build, the reports that reference the dll all have similar errors (depending on which property is calling the dll).
Most research says to put the dll into several different folders:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\SSRS
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PrivateAssemblies
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies
As well as to change values in:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\SSRS\RSPreviewPolicy.config to PermissionSetName="FullTrust"
I've deleted the file from all locations including the debug\bin directory of the dll project and rebuilt the dll. It went into the PrivateAssemblies folder automatically and I put it in the other directories. I removed/re-referenced the dll in the WinForms app, restarted the computer, etc. Nothing has helped. Everything used to work in Visual Studio 2017. I've excluded all reports in the project so it would build successfully, and it did. But when I added back even 1 report, I still got the errors.
Please help!
Here's and example of one of the error messages I get on the report "ActivityLog.rdlc"
Severity Code Description Project File Line Suppression State
Error Error while loading code module: ‘RDLFunctions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Details: Could
not load file or assembly 'RDLFunctions, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file
specified. Reports C:\SourceCode\Atlas\Mwells-Development-branch\Reports\Claims\ActivityLog.rdlc
copy the dll file to folder:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin
it's will work.
i'm using Visual Studio Enterprise 2019, Version 16.5.0

Failure adding assembly to the cache: This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

I am having this same problem:
IsVisualStudio2012ProInstalled() method not found error when running an SSIS package from VS2012 (I didn't have enough rep to comment and ask for help there). This issue started when I had visual studio 2012 installed but then installed visual studio 2015, the shop I work for uses both.
I followed the instructions of the #1 answer but getting the error below
I've entered this in command prompt:
C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\PrivateAssemblies>"C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\Bin\gacutil.exe" /if Microsoft.SqlServer.Dts.Design.dll
Error:
Failure adding assembly to the cache: This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
I finally got this to work by finding a newer version of gacutil that was on my computer. You can see originally I was looking in the v7.0a folder but found another copy in a v8.0a folder that I used that worked.
cd "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bin\NETFX 4.0 Tools\gacutil.exe"
/if Microsoft.SqlServer.Dts.Design.dll

"cannot open source file"- headers included, Visual Studio 2015

I keep receiving the error "cannot open source file" in Visual Studio 2015 when trying to compile the "simpleLite.c" from AR Toolkit. This occurs despite placing the the full paths to the headers in the project options include setting and also pasting the headers into the project headers folder.
AR Toolkit is installed as C:\Program Files (x86)\ARToolKit5
The include paths, which are pasted into the project include setting, are:
C:\Program Files (x86)\ARToolKit5\include\AR;
C:\Program Files (x86)\ARToolKit5\include\win32-i386\GL
All include files fail to open:
Is anyone aware of additional needed configuration?
The include paths, which are pasted into the project include setting, are: C:\Program Files (x86)\ARToolKit5\include\AR; C:\Program Files (x86)\ARToolKit5\include\win32-i386\GL
Seeing that the #include directives start with AR and GL, you probably should not have those subdirectories in your include paths, but just
C:\Program Files (x86)\ARToolKit5\include; C:\Program Files (x86)\ARToolKit5\include\win32-i386

Use visual studio default include folder to add library header files

I am using libsodium in a c project using visual studio with the normal way of including headers and lib file with "Additional Headers Directories" and "Additional Library Directories".
What I want to ask if it is possible to add the headers to
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include"
and the .lib file to
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib"
so that it is included by default in any project I use ? and if it would be considered bad practice ?
Thanks

Reference error while compiling C file in VS2010 command-prompt

I have VS 2010 installed on my system and i was trying to compile a simple hello.c in VS command prompt. The compilation gave an error.
Fatal Error C1083: Cannot open include file: 'stdio.h' no such file, folder exist
Why this error is coming ?? Does VS2010 not include reference files/assemblies for C.
VS 2010 certainly does contain the standard headers. You should check that your command prompt environment is set up correctly. There should be an environment variable named INCLUDE that has a directory similar to the cfollowing (among other directories) in it:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE
that directory (the name may vary slightly, for example depending on if your machine is a 64-bit OS of not) should include stdio.h
If you don't have such a directory in your environment, then you're not setting up the environment correctly. You should use on of the "Visual Studio Command Prompt" shortcuts that VS installs, or simply run
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
With the appropriate parameter to get the environment you want (x86 or amd64 for example).
If the INCLUDE environment variable does have an entry like that, but the stdio.h file doesn't exist, then you might need to reinstall VS.
I had a similar problem as the OP the VC folder was missing most of the files. I tried both repairing and uninstalling/reinstalling VS 2010 but neither worked.
What worked for me was installing the Microsoft Visual C++ 2010 Redistributable Package (x86).Microsoft Visual C++ 2010 Redistributable Package (x86)
There are so many versions of so much Windows system code that it's easy for a path to become invalid.
In my case:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
needed to be changed to::
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
i.e. v7.1A -> v7.0A (don't ask why, it just part of the everyday, tiresome task of dealing with Microsoft!).
I had the same problem. The file stdio.h did not exist in folder include. I removed VS 2010 using the Control Panel then reinstalled, but this didn't solve the problem.
I then used the VS 2010 installation CD to remove all of VS 2010, and manually removed anything leftover by Control Panel. I then installed VS 2010 professional again. The problem was solved.

Resources