Compiling amalgamation with Visual Studio 2019
(1) By anonymous on 2021-01-28 09:17:41 [link] [source]
I am trying to compile the source code from here1 using Visual Studio 2019 & I am getting the following two errors:
|Error||C1083||Cannot open include file: 'stdlib.h': No such file or directory||SQLite3||shell.c||85|
|Error||C1083||Cannot open include file: 'malloc.h': No such file or directory||SQLite3||xmmintrin.h||79|
I've tried to troubleshoot this using Google search & haven't managed to overcome these two errors.
I am sure this is a VS2019 configuration issue but it might relate to the source code.
Please, could someone with insight into this specific problem help me pin-point the resolution for these two issues? Thanks.
1This is the download link with description:
C source code as an amalgamation, version 3.34.1. (sha3: be0d07b08969aa775c628f214c723955c0bfe880d72c3289a1ff54ad779b15d3)
(2) By Gunter Hick (gunter_hick) on 2021-01-28 10:13:08 in reply to 1 [link] [source]
VS is not finding the linux standard library headers. This is a configuration problem in VS and has nothing to do with SQLite. You need to set the include path for VS correctly.
(3) By anonymous on 2021-01-28 10:23:01 in reply to 2 [link] [source]
Thanks for your response. I am using:
Microsoft Visual Studio Enterprise 2019
on Windows 10. VS2019 is fully up to date.
VS is not finding the linux standard library headers.
I do not understand this, that is, the reference to linux.
has nothing to do with SQLite
Not directly, I realise that; however, I am trying to compile SQLite3.
You need to set the include path for VS correctly.
Please give me a clue (C/C++ is not my domain) to help me do this.
(4) By TripeHound on 2021-01-28 10:50:05 in reply to 3 [link] [source]
The reference to "linux" is (IMHO) slightly misleading: they are part of the "standard C library headers", and are/should-be present on both Linux and Windows (at least when suitable dev-tools, such as Visual Studio, are installed).
Out of the box (in my experience), Visual Studio SHOULD know where these are, and SHOULD know to use them: you would normally have to take deliberate steps for it not to find them.
For instance, using the "Community" edition of Visual Studio 2019, I just downloaded that zip file and -- with the Visual Studio environment enabled (i.e. having run
VsDevCmd.bat) -- I can just type:
cl shell.c sqlite3.c
and it creates
shell.exe with no problems.
So: How are you trying to compile? Through the IDE or from the command-line? Are you trying to compile the shell, or link the SQLite code into an existing project? Have you changed any of the default options in the IDE?
(5) By anonymous on 2021-01-28 11:36:32 in reply to 4 [link] [source]
C/C++ is virtually alien to me; I use C#.
How are you trying to compile?
I have Visual Studio 2019 Enterprise. I extracted the file from the download and copied the following file into a new directory:
shell.c sqlite3.c sqlite3.h sqlite3ext.h
From the VS2019 IDE
- I select File | New | Project from Existing Code and select my directory where the above files are.
- I select Build | Batch Build and click Rebuild.
That takes to the errors I reported in my original post.
As far as I am aware, I have made no configuration changes in VS2019.
having run VsDevCmd.bat
I believe that is the Visual Studio Command Prompt. I found several versions of CL.EXE. Using this version:
"D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023bin\Hostx86\x86\cl.exe"
(I can't find the command prompt for VS2019, only the one for VS2017.)
I tried your suggestion, namely,
cl shell.c sqlite3.c
This gives me the following:
E:\Ajay\C#\VS2019\SQLite3shell.c(85): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory sqlite3.c
D:Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\xmmintrin.h(79): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory ```
If you look carefully, this is exactly the errors that the VS2019 gave me - see above.
So I am no further forward. CL.EXE would not be looking at the VS2019 configurations.
What I find strange is that using the same approach, I was able to compile the source code for v3.33 with VS2019 - which, now, no longer compiles.
I am still missing something!
(6) By anonymous on 2021-01-28 12:00:43 in reply to 5 [link] [source]
Same outcome using the VS2019 Command Prompt, which I launched from the IDE.
(8) By Bill Wade (wwade) on 2021-01-28 12:42:58 in reply to 6 [link] [source]
Using the VS GUI installer, be sure you've selected and installed "Desktop development with C++". If you've done that, stdlib.h should be available.
(7) By Richard Hipp (drh) on 2021-01-28 12:42:46 in reply to 5 [link] [source]
I'm guessing that your VS2019 install is defective. Any C compiler that cannot find "stdlib.h" has issues.
(10) By anonymous on 2021-01-28 14:04:14 in reply to 7 [link] [source]
Any C compiler that cannot find "stdlib.h" has issues.
I have repaired my VS2019 installation & kept it up to date (I normally use it for C# only). I cannot uninstall and then re-install using the same license - only one installation per key.
Somehow, some setting in VS2019 has got 'installed/misplaced/corrupted' that is telling VS2019 to look for stdlib.h where it isn't.
As I mentioned, C/C++ is alien to me but I had managed to compile v3.33 earlier on (but can no longer do that either). I'll try Keith's suggestion  next.
(9) By Keith Medcalf (kmedcalf) on 2021-01-28 13:05:38 in reply to 5 [link] [source]
Run VsDevCmd.bat then look at the INCLUDE variable setting by typing SET INCLUDE
You should get back a whole raft of stuff like this:
INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;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\shared;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\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt
And in one of those directories (it is a ; (semicolon) separated list of paths where to find #include files) should reside stdlib.h. (Probably the very first one, since that is the the "compiler's own home", the others are the various Windows Develepment Kits and SDKs and other stuff that accumulates around windows.
The message is telling you that the file cannot be found when searching the INLCUDE path. Either because of crappy inherent design flaws (spaces in file names, using a drive letter other than drive C, etc, things that have been persistent annoyances in Windows since the time of the beginning).
If it once worked and now doesn't that means you changed something between then and now that caused that situation and you need to "unchange" whatever you changed. Or you can try telling the Visual Studio installer to "fix" itself, or uninstall and re-install it.
(11) By Keith Medcalf (kmedcalf) on 2021-01-28 14:38:13 in reply to 9 [link] [source]
Note that for me I found stdlib.h in
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt
which is what the Visual Studio Installer calls the "Windows Universal C Runtime". You need to ensure on the individual components page of the VS Installer thingy that "Windows 10 SDK" of some version and "Windows Universal C Runtime" are selected.
It would appear that Microsoft has been playing musical chairs and moving things about when they updated their diapers by renaming things again recently.
(12.2) By Keith Medcalf (kmedcalf) on 2021-01-28 16:11:57 edited from 12.1 in reply to 11 [link] [source]
I have the following Individual Components installed to get the command line compiler working. This appears to be the minimum set of components required to get the Visual Studio Build Tools to work.
Code Tools Text Template Transformation Compilers, Build Tools, and Runtimes C++ 2019 Redistributable Update MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.28) MSVC v142 - VS 2019 C++ x64/x86 Spectre-mitigated libs (v14.28) Debuging and Testing C++ Build Tools core features C++ core features Development activities C++ Build Tools core features C++ core features SDKs Libraries and Frameworks Windows 10 SDK (10.0.19041.0) Windows Universal Runtime
Some are forced on by the installer itself, the spectre-mitigated libs I added manually.
NB: .NET support removed saving about 1 GB of space
NBB: works for pure C/C++ including SQLite3 and Python
(13) By Larry Brasfield (LarryBrasfield) on 2021-01-28 15:46:35 in reply to 1 [source]
This answer is for anybody having difficulty with the (thread) subject.
When Visual Studio is installed, there are many feature options. At an early stage of the installation, these options can be selected via a dialog box. The same dialog is presented when an existing installation is modified (by launching the "Visual Studio Installer", a shortcut placed in the "Visual Studio 20##" folder in the Start Menu.) The option, "Desktop development with C++" must be checked. There are suboptions, most of which are not strictly needed to compile SQLite. The suboptions tagged "MSVC v### ..." and "Windows ## SDK ..." should be checked. Then the installation (or its modification) can be told to proceed to completion.
If the installation for it has been done, the Start Menu will have a folder tagged "Visual Studio 20##" which contains one or more shortcuts tagged "... Tools Command Prompt" where the elided part indicates various combinations of host and target platform (x86 or x64) and "Native" or "Cross" compilation.
Launching one of those "... Tools ..." shortcuts will start a command-line shell, cmd.exe, known as "the command prompt" or sometimes (incorrectly) "DOS prompt". That shell will have its INCLUDE, LIB, LIBPATH and PATH environment variables set or modified such that useful command-line tools such as CL.exe, LINK.exe, LIB.exe, RC.exe, DUMPBIN.exe and NMAKE.exe can be found among the directories named in %PATH% and those tools can find "#include <whatever.h>" header files and commonly used system link libraries, among others.
To build the SQLite library or its shell, sqlite3.exe, How To Compile SQLite should be studied and heeded. There, the use of an NMAKE script, "Makefile.msc", distributed with the "sqlite-autoconf-3######.tar.gz" forms of the amalgamation archive is described. Building with MSVC without the benefit of that makefile is a complex subject, best left to experts or those willing to learn NMAKE and study that makefile.
The makefile implements many build options and targets. By default, it builds the sqlite3.exe CLI shell with the SQLite library statically linked. It can be told to build the library as a DLL. Debug and normal builds can be specified. To see all the options, learn rudimentary "make" syntax and study the makefile.