I’m trying to install PG Vector on Windows following the instructions from the GitHub repository. I’ve installed the necessary C++/C compiler environment (GNU) and set up the path variable for nmake to:
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x86
When I run the command nmake /F Makefile.win from the Visual Studio Developer Command Prompt, I encounter the following error:
D:\pg_vector_clone\pgvector>Microsoft (R) Program Maintenance Utility
Version 14.44.35217.0 'Microsoft' is not recognized as an internal or
external command, operable program or batch file.
D:\pg_vector_clone\pgvector>Copyright (C) Microsoft Corporation. All
rights reserved. 'Copyright' is not recognized as an internal or
external command, operable program or batch file.
D:\pg_vector_clone\pgvector> D:\pg_vector_clone\pgvector> cl
/nologo /I"C:\Program
Files\PostgreSQL\18\include\server\port\win32_msvc" /I"C:\Program
Files\PostgreSQL\18\include\server\port\win32" /I"C:\Program
Files\PostgreSQL\18\include\server" /I"C:\Program
Files\PostgreSQL\18\include" /O2 /fp:fast /c src\bitutils.c
/Fosrc\bitutils.obj bitutils.c
D:\pg_vector_clone\pgvector>bitutils.c 'bitutils.c' is not recognized
as an internal or external command, operable program or batch file.
D:\pg_vector_clone\pgvector>C:\Program
Files\PostgreSQL\18\include\server\pg_config_os.h(29): fatal error
C1083: Cannot open include file: 'crtdefs.h': No such file or
directory 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
D:\pg_vector_clone\pgvector>NMAKE : fatal error U1077: 'cl /nologo
/I"C:\Program Files\PostgreSQL\18\include\server\port\win32_msvc"
/I"C:\Program Files\PostgreSQL\18\include\server\port\win32"
/I"C:\Program Files\PostgreSQL\18\include\server" /I"C:\Program
Files\PostgreSQL\18\include" /O2 /fp:fast /c src\bitutils.c
/Fosrc\bitutils.obj' : return code '0x2' NMAKE : U1065: invalid
option ':' Stop.
D:\pg_vector_clone\pgvector>Stop. 'Stop.' is not recognized as an
internal or external command, operable program or batch file.
I’m unable to understand what I’m missing here. Can someone help me resolve this “fatal error C1083: Cannot open include file: ‘crtdefs.h’: No such file or directory” when installing PG Vector on Windows?
The “fatal error C1083: Cannot open include file: ‘crtdefs.h’: No such file or directory” error when installing PG Vector on Windows typically occurs due to missing Windows SDK files or incorrect Visual Studio setup. This error indicates that the C compiler cannot find the crtdefs.h file, which is part of the Visual C++ runtime and Windows SDK components.
Contents
- Understanding the crtdefs.h Error
- Common Causes of the Error
- Step-by-Step Solutions
- Alternative Installation Methods
- Troubleshooting Additional Issues
- Best Practices for Windows Installation
Understanding the crtdefs.h Error
The crtdefs.h file is a critical header file in the Visual C++ runtime environment that contains important definitions for C standard library functions. When this file is missing or cannot be found during the pgvector compilation process, the build fails with the C1083 error.
According to Microsoft’s documentation, this error commonly occurs when:
- Windows SDK is not properly installed or corrupted
- Visual Studio is missing required C++ components
- Environment variables are incorrectly configured
- Wrong command prompt is being used for compilation
The error specifically points to pg_config_os.h(29) trying to include crtdefs.h, which means the PostgreSQL build system is attempting to compile using Visual Studio tools but cannot locate the necessary header files.
Common Causes of the Error
Based on research from multiple sources, here are the most common causes of the crtdefs.h error:
1. Missing Windows SDK Components
The Windows SDK contains the crtdefs.h file and related C runtime headers. If the SDK is not installed or is incomplete, compilation will fail.
2. Incorrect Visual Studio Installation
Visual Studio installations may not include all necessary C++ build tools by default, especially in “Build Tools” editions.
3. Wrong Command Prompt Environment
Using a regular Command Prompt instead of the Visual Studio Native Tools Command Prompt can cause path and environment issues.
4. Corrupted Installation Files
Sometimes, partial or corrupted Visual Studio/SDK installations can lead to missing system files.
5. Path Configuration Issues
Incorrect environment variables or paths can prevent the compiler from finding the necessary files.
Step-by-Step Solutions
Solution 1: Verify and Reinstall Windows SDK
-
Check Windows SDK Installation:
- Open Visual Studio Installer
- Select your installation and click “Modify”
- Ensure “Windows 10 SDK” or “Windows 11 SDK” is installed (version 10.0.19041.0 or later recommended)
-
Reinstall Windows SDK if Missing:
- Download and install the latest Windows SDK from Microsoft’s website
- During installation, select “C++ build tools” component
Note: As suggested on Stack Overflow, “Reinstall windows 10 sdk, if you missing windows sdk or if its content changed this error will popup”
Solution 2: Configure Visual Studio Properly
-
Use Correct Command Prompt:
- Open “x64 Native Tools Command Prompt for VS 2022”
- This ensures proper environment variables are set
- Navigate to your pgvector directory and try compilation again
-
Verify Visual Studio Components:
- In Visual Studio Installer, ensure these components are installed:
- MSVC v143 - VS 2022 C++ x64/x86 build tools
- Windows 10/11 SDK
- C++ CMake tools for Windows
- In Visual Studio Installer, ensure these components are installed:
Solution 3: Set Environment Variables
-
Add MSVC Tools to Path:
bashset PATH="C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64;%PATH%" -
Set Include Directories:
bashset INCLUDE="C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include;%INCLUDE%"
Solution 4: Clean and Rebuild
-
Clean the Build:
bashnmake /F Makefile.win clean
-
Rebuild the Extension:
bashnmake /F Makefile.win
Alternative Installation Methods
Method 1: Using Conda (Recommended)
If you’re having trouble with the manual compilation, you can use conda to install pgvector:
conda install -c conda-forge pgvector
This method avoids the compilation issues entirely and is the recommended approach for Windows users, as mentioned in the Stack Overflow discussion.
Method 2: Using Precompiled Binaries
Check if precompiled binaries are available for your PostgreSQL version from the pgvector releases page.
Method 3: Using Docker
Run pgvector in a Docker container to avoid Windows-specific compilation issues:
docker run -d --name pgvector -e POSTGRES_PASSWORD=yourpassword -p 5432:5432 pgvector/pgvector:pg16
Troubleshooting Additional Issues
Issue: “nmake is not recognized”
If you get “nmake is not recognized” error:
- Ensure you’re using the correct Visual Studio Command Prompt
- Add the nmake path to your system PATH:
C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64
Issue: “pg_config.h not found”
This typically means PostgreSQL development headers are missing:
- Install PostgreSQL development package or
- Set PGROOT environment variable:bash
set PGROOT="C:\Program Files\PostgreSQL\18"
Issue: “Case value ‘4’ already used”
According to the Windows installation guide, this error occurs when you’re not using the x64 Native Tools Command Prompt. Always use the correct command prompt for your target architecture.
Best Practices for Windows Installation
1. Always Use Visual Studio Native Tools Command Prompt
This ensures proper environment variables are set for compilation.
2. Verify All Dependencies Before Starting
- Check PostgreSQL installation path
- Verify Visual Studio components
- Ensure Windows SDK is installed
3. Keep Software Updated
- Use the latest PostgreSQL version
- Keep Visual Studio/Build Tools updated
- Use recent Windows SDK versions
4. Consider Alternative Installation Methods
For Windows users, conda installation is often more reliable than manual compilation.
5. Document Your Environment
Keep track of:
- PostgreSQL version and installation path
- Visual Studio version and build tools
- Windows SDK version
- Any custom environment variables
Conclusion
The “crtdefs.h: No such file or directory” error is a common compilation issue when installing pgvector on Windows, typically caused by missing Windows SDK components or incorrect Visual Studio setup. The most reliable solutions include:
- Reinstall Windows SDK to ensure all necessary C runtime files are present
- Use the correct command prompt - x64 Native Tools Command Prompt for VS 2022
- Verify Visual Studio installation includes all required C++ build tools
- Consider alternative installation methods like conda for Windows users
For future installations, using conda (conda install -c conda-forge pgvector) is recommended as it avoids many Windows-specific compilation issues entirely. Always ensure your development environment is properly configured before attempting to compile extensions from source.
If you continue to experience issues, consider reaching out to the pgvector GitHub community for specific troubleshooting assistance with your setup.
Sources
- Stack Overflow - Unable to install pgvector extension for PostgreSQL Windows
- GitHub Issue - crtdefs.h not found issue while running command nmake /F Makefile.win
- Microsoft Q&A - How do I fix this issue: C1083 Cannot open include file: ‘corecrt.h’: No such file or directory
- Stack Overflow - Cannot find corecrt.h: $(UniversalCRT_IncludePath) is wrong
- pgvector4Windows Installation Guide
- GitHub Issue - Failed to nmake on postgress 16 [windows]
- Stack Overflow - Cannot open include file: ‘libintl.h’ Windows 11