0

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

ontheshore
  • 59
  • 1
  • 5
  • 1
    Would just `/DWIN32` do? Remove all that `/property` stuff too. – Ken Y-N May 14 '21 at 08:18
  • Who told you about `/property`? Which documentation did you read about that? And AFAIK the MSVC compiler `cl` doesn't really have any other target than WIN32 so that "platform" should be default. – Some programmer dude May 14 '21 at 08:24
  • @KenY-N : Yes it solves the issue but gives other errors: Please see the edited main content. – ontheshore May 14 '21 at 08:32
  • @Someprogrammerdude : Yes WIN32 is default. In that case why does Port.h flag the error mentioned ? Setting the platform by command line is mentioned in https://stackoverflow.com/questions/3155492/how-do-i-specify-the-platform-for-msbuild – ontheshore May 14 '21 at 08:45
  • That question and its answers is for the `msbuild` tool, not the `cl` compiler. – Some programmer dude May 14 '21 at 08:57

0 Answers0