I want to compile without linking a .c code [ say xyz.c ] which would be used in future as multithreaded dll. I used the following command in developer command prompt (visual studio 2019),
cl /c /MD xyz.c
it results in the following error:
xyz.c C:\Spice\source\include\port.h(101): error C2061: syntax error: identifier 'error'
C:\Spice\source\include\port.h(101): error C2059: syntax error: ';'
C:\Spice\source\include\port.h(103): error C2061: syntax error: identifier 'system'
C:\Spice\source\include\port.h(103): error C2059: syntax error: ';'
C:\Spice\source\include\port.h(103): error C2061: syntax error: identifier 'unknown'
C:\Spice\source\include\port.h(105): error C2061: syntax error: identifier 'error'
C:\Spice\source\include\port.h(105): error C2059: syntax error: ';'
Generating Code...
The reason for the error is that one of the header files port.h checks for #ifdef WIN32 and returns false. The relevant lines from port.h are shown below:
#ifdef WIN32 // Support for Windows OS \
#include "os_win32.h" \
#define CONFIGURED \
#endif \
#ifndef CONFIGURED \
error error error error \
Operating system type unknown \
error error error error \
#endif
Since WIN32 is a platform name, i tried to set it as follows:
cl /c /MD xyz.c /property:Configuration=Debug /property:Platform=Win32
Thus I naively used the aforementioned command meant to be used with MSBuild in the hope that setting the platform name would automatically cause WIN32 to be defined and that would solve the issue. However, these extra options were ignored by compiler and the following warning were issued:
cl : Command line warning D9002 : ignoring unknown option '/property:Configuration=Debug'
cl : Command line warning D9002 : ignoring unknown option '/property:Platform=Win32' \
So how to [set the platform to WIN32] / [cause WIN32 to be defined] by command line ? ---------------------EDIT 1------------------------- If one modifies the command to
cl /DWIN32 /c /MD xyz.c
then it results in the following error:
xyz.c C:\Spice\source\include\capabil.h(128): warning C4273: 'logb': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\corecrt_math.h(517): note: see previous definition of 'logb'
C:\Spice\source\include\capabil.h(136): warning C4273: 'erfc': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\corecrt_math.h(499): note: see previous definition of 'erfc'
Generating Code... C:\Spice\bin\ifspec.c : fatal error C1083: Cannot open compiler generated file: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\ifspec.obj': Permission denied