Nalina has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I installed Microsoft Visual Studio .NET. Now when I tried to compile my perl_inc.c program as in my earlier thread I still am getting some errors
E:\>cl.exe -DWIN32 -I"C:\Perl\lib\CORE" C:\Perl\lib\CORE\perl58.lib -o + perl_inc.exe perl_inc.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for +80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. perl_inc.c C:\Perl\lib\CORE\sys/types.h(20) : fatal error C1083: Cannot open incl +ude file:'_ansi.h': No such file or directory
Then I tried to compile a simple program hello.c
#include <stdio.h> int main() { printf("Hello World\n"); return 0; }
I got an error saying
E:\>cl.exe -DWIN32 -I"C:\Perl\lib\CORE" C:\Perl\lib\CORE\perl58.lib -o + hello.exe hello.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for +80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. hello.c Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. /out:hello.exe /out:hello.exe C:\Perl\lib\CORE\perl58.lib hello.obj LINK : fatal error LNK1104: cannot open file "LIBC.lib"
But libc.lib is found in 'C:\Perl\lib\CORE' directory. I don't understand why I am getting these errors? I am fed up. Please help me.

Replies are listed 'Best First'.
Re: cl.exe & _ansi.h
by tachyon (Chancellor) on Aug 25, 2004 at 08:22 UTC

    Will you please read A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++ and follow the instructions. If you do what it says there and it still won't work.....

    You second example is just wrong. To compile hello.c with your INCLUDE and LIB env vars set, and the correct bits in your path all you need to do is:

    cl hello.c

    It should be that easy. Here is an approximation of what your PATH, LIB and INCLUDE env vars should look like:

    C:\>set PATH Path=D:\Perl\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C: +\COREL50;C:\Program Files\SSH Communications Security\SSH Secure Shel +l ;C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin;C:\Program File +s\Common Files\Microsoft Shared\VSA\7.0\VsaEnv C:\>set LIB LIB=C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Lib\;d: +\tools\cl\lib\ C:\>set INCLUDE INCLUDE=C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\inc +lude\;d:\tools\cl\include\ C:\>cl hello.c Microsoft (R) 32-bit C/C++ Standard Compiler Version 13.00.9466 for 80 +x86 Copyright (C) Microsoft Corporation 1984-2001. All rights reserved. hello.c Microsoft (R) Incremental Linker Version 7.00.9466 Copyright (C) Microsoft Corporation. All rights reserved. /out:hello.exe hello.obj C:\>hello Hello World

    Here is a quick explanation of the various bits you are seeing in the command line of a linked widget like the embedded interpretter that this is all about:

    cl.exe -DWIN32 -I"C:\Perl\lib\CORE" C:\Perl\lib\CORE\perl58.lib -o int +erp.exe interp.c 1 2 3 4 5 + 6
    1. cl.exe This is the MS compiler. The exe is optional as Win32 will look for a cl.exe and cl.com and cl.bat if you just type 'cl'
    2. -DWIN32 This is a define - it defines the compiler token WIN32*
    3. -I"C:\Perl\lib\CORE" This is where to look for included headers, in addition to any default locations set via the INCLUDE env var
    4. C:\Perl\lib\CORE\perl58.lib This is a compiled library that we are going to link to. While the header file typically just contains a function definition, the library code contains the real guts of the code. When you don't have all the required libs available the compiler will typically die saying can't find entry point _some_function.
    5. -o interp.exe This instructs the comiler to output the executable to interp.exe. With cl.exe if the input file is called blah.c then it will produce blah.exe by default. gcc by contrast would produce a.out if you don't specify the name
    6. interp.c This is what we are actually compiling

    * DEFINES

    Here is a snippet from perl.c

    #if defined(WIN32) incpush(PRIVLIB_EXP, TRUE, FALSE); #else incpush(PRIVLIB_EXP, FALSE, FALSE); #endif

    When we compile with -DWIN32 the WIN32 token will be defined, so the first incpush() will be compiled, while the second is simply stripped and ignored. If the WIN32 token is not defined then the reverse will happen.

    cheers

    tachyon

Re: cl.exe & _ansi.h
by Anonymous Monk on Aug 25, 2004 at 07:35 UTC
    But libc.lib is found in 'C:\Perl\lib\CORE' directory.
    libc.lib is not part of perl and should not be in perl\lib\CORE.
Re: cl.exe & _ansi.h
by Anonymous Monk on Aug 25, 2004 at 07:39 UTC
      Please make sure that the PATH variables are set appropriately. Also check environment variables INCLUDE and LIB on the machine.
      I am fed up.

      I agree. Perhaps it's time we said "Heeeere's your sign."

      --
      tbone1, YAPS (Yet Another Perl Schlub)
      And remember, if he succeeds, so what.
      - Chick McGee

Re: cl.exe & _ansi.h
by gellyfish (Monsignor) on Aug 25, 2004 at 09:49 UTC

    You need to this from the "Visual Studio .NET Command Prompt" which is on the Visual Studio .NET tools sub-menu rather than just from a plain cmd.exe prompt, this is essentially a batch file that sets the correct environment for the command line tools to work properly and find everything they need.

    /J\

      You need to this from the "Visual Studio .NET Command Prompt"

      That is simply wrong. You don't, it works just fine off the cmd.exe command line, all you have to do is set the PATH, LIB, INCLUDE env vars as detailed above. See here for example of running it off the normal command line.

      cheers

      tachyon

        all you have to do is set the PATH, LIB, INCLUDE env vars as detailed above

        Er, precisely, and what is the easiest way of doing this in the correct way for the configuration of the system? Oh yes, using the "Visual Studio .NET Command Prompt" which runs a handy little batch file that does all that stuff for you. I don't see any sense where that is "wrong" at all. In retrospect perhaps I should have replaced "need" with "will find this easier if". *shrug*

        /J\