Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Perl & borland 5.5 C/C++ Compiler

by tachyon (Chancellor)
on Aug 24, 2004 at 07:50 UTC ( #385348=note: print w/replies, xml ) Need Help??

in reply to Perl & borland 5.5 C/C++ Compiler

In a nutshell you need to compile your code with the same compiler that compiled perl. If you are using Active State Perl the compiler is cl.exe which is part of MSVC++. See A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++ for some hints.

It works fine for me using the setup described and cl.exe:

# Have a look at the options perl was built with (we don't need all of + them!)...... C:\>perl -MExtUtils::Embed -e ccopts -e ldopts -nologo -nodefaultlib -debug -opt:ref,icf -libpath:"D:\Perl\lib\COR +E" -machine:x86 D:\Perl\lib\CORE\perl56.lib D:\Perl\lib\CORE\oldnam +e s.lib D:\Perl\lib\CORE\kernel32.lib D:\Perl\lib\CORE\user32.lib D:\Per +l\lib\CORE\gdi32.lib D:\Perl\lib\CORE\winspool.lib D:\Perl\lib\CORE\c +o mdlg32.lib D:\Perl\lib\CORE\advapi32.lib D:\Perl\lib\CORE\shell32.lib +D:\Perl\lib\CORE\ole32.lib D:\Perl\lib\CORE\oleaut32.lib D:\Perl\lib\ +C ORE\netapi32.lib D:\Perl\lib\CORE\uuid.lib D:\Perl\lib\CORE\ +b D:\Perl\lib\CORE\mpr.lib D:\Perl\lib\CORE\winmm.lib D:\Perl\lib\COR +E \version.lib D:\Perl\lib\CORE\odbc32.lib D:\Perl\lib\CORE\odbccp32.lib + D:\Perl\lib\CORE\msvcrt.lib -nologo -O1 -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DE +S_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_R +E ADFIX -I"D:\Perl\lib\CORE" # here is the code C:\>type interp.c #include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ static PerlInterpreter *my_perl; /* The Perl interpreter */ int main(int argc, char **argv, char **env) { my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, (char **)NULL); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); } # Here are the flags that I passed to make it compile # Essentially we pass all the same -D defines that perl was built with + plus # the include dir to find the perl headers and the perl56.lib binary w +hich is # what where the real functions defined in the headers are found and w +hat we # will be linking against........ C:\>cl.exe -nologo -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT - +DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_ +MSVCRT_READFIX -I"D:\Perl\lib\CORE" D:\Perl\lib\CORE\perl56.lib -o +interp.exe interp.c interp.c # no messages, no errors, so let's test it...... C:\>interp.exe print "Hello World! It will work if you try hard enough.....\n"; ^D Hello World! It will work if you try hard enough..... C:\> # the bare minimum I needed to get a compile is this C:\>cl.exe -DWIN32 -I"D:\Perl\lib\CORE" D:\Perl\lib\CORE\perl56.lib -o + interp.exe interp.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. interp.c Microsoft (R) Incremental Linker Version 7.00.9466 Copyright (C) Microsoft Corporation. All rights reserved. /out:interp.exe /out:interp.exe D:\Perl\lib\CORE\perl56.lib interp.obj C:\>interp.exe print "japh!\n"; ^D japh! C:\>



Replies are listed 'Best First'.
Re^2: Perl & borland 5.5 C/C++ Compiler
by blm (Hermit) on Aug 24, 2004 at 12:03 UTC

    With all due respect the question was not related to cl.exe or using Microsoft Visual Studio tools it was about compiling an exe with a perl interpreter embedded with the Borland C++ Free Command Line tools. It may work with cl.exe but not all of us have access to Visual Studio.

    In order to help I went and downloaded Perl 5.8.5 stable.tar.gz and compiled it with the Borland C++ Free Command Line tools with the help of the documentation in README.win32. That was mostly ok except the reliance on rcl.exe was not mentioned in README.win32 as far as I can tell. This tool can be obtained in the MS Platform SDK and seems to be in Visual Studio.NET and Microsoft VB 6 (98)

    When I went to compile the authors code I still had problems. Even making sure that I checked the build options with

    C:\>perl -MExtUtils::Embed -e ccopts -e ldopts -tWD -L"c:\perl\lib\CORE" -L"C:\borland\bcc55\lib" -Gn C:\perl\lib\ +CORE\perl5 8.lib C:\borland\bcc55\lib\import32.lib C:\borland\bcc55\lib\cw32mti.l +ib -O2 -D_RTLDLL -DWIN32 -DHAVE_DES_FCRYPT -D_MT -D__USELOCALES__ -D_WIN +32_WINNT=0 x0410 -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -I"C:\perl\lib\CORE +" C:\>

    Now the -Gn option gives an error so I removed that but I get the following still when I compile

    C:\>bcc32 -tWD -Ic:\perl\lib\core -L"c:\perl\lib\CORE" -L"C:\borland +\bcc55\lib " C:\perl\lib\CORE\perl58.lib C:\borland\bcc55\lib\import32.lib C:\bo +rland\bcc5 5\lib\cw32mti.lib perl_inc.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland perl_inc.c: Error E2303 c:\perl\lib\core\win32.h 312: Type name expected Error E2293 c:\perl\lib\core\win32.h 411: ) expected Error E2293 c:\perl\lib\core\perlio.h 105: ) expected Error E2293 c:\perl\lib\core\perlio.h 106: ) expected Error E2293 c:\perl\lib\core\perlio.h 108: ) expected Error E2293 c:\perl\lib\core\perlio.h 110: ) expected Error E2141 c:\perl\lib\core\perlio.h 111: Declaration syntax error Error E2293 c:\perl\lib\core\perlio.h 112: ) expected Error E2293 c:\perl\lib\core\perlio.h 214: ) expected Error E2293 c:\perl\lib\core\perlio.h 227: ) expected Error E2303 c:\perl\lib\core\perlio.h 339: Type name expected Error E2303 c:\perl\lib\core\perlio.h 342: Type name expected Error E2293 c:\perl\lib\core\perlio.h 345: ) expected Error E2293 c:\perl\lib\core\perlio.h 354: ) expected Error E2293 c:\perl\lib\core\perlio.h 358: ) expected Error E2293 c:\perl\lib\core\perlio.h 365: ) expected Error E2293 c:\perl\lib\core\perlio.h 370: ) expected Error E2303 c:\perl\lib\core\win32iop.h 73: Type name expected Error E2303 c:\perl\lib\core\win32iop.h 74: Type name expected Error E2303 c:\perl\lib\core\win32iop.h 77: Type name expected Error E2303 c:\perl\lib\core\win32iop.h 133: Type name expected Error E2238 c:\perl\lib\core\perl.h 1775: Multiple declaration for 'AV +' Warning W8017 c:\perl\lib\core\dosish.h 142: Redefinition of 'Stat' is + not identical Error E2257 c:\perl\lib\core\perl.h 2074: , expected Error E2257 c:\perl\lib\core\perl.h 2075: , expected Error E2257 c:\perl\lib\core\perl.h 2076: , expected Error E2228 c:\perl\lib\core\perl.h 2076: Too many error or warning me +ssages *** 26 errors in Compile ***

    Now I am tired but I cursory look into 'c:\perl\lib\core\win32.h' didn't reveal anything blatantly erroneous but I could be wrong. I also know that the authors code should work because you have tested it with Visual Studio and I tested it on FreeBSD 4.8-STABLE with perl 5.8.3. So maybe there is breakage in building with Borland bcc32.exe? I beleive bcc32.exe is a compiler that "is supported" for building perl.

    You will note however that the errors that I get are very similar if not the same as what Nalina was getting

      Actually my suggestion to use cl.exe is possibly valid, but simply based on the fact that IMHO it works better so I use it. With cl.exe come the header and library files you need to link apps under windows. These are of course the M$ versions. When you get BCC you get Borlands take on these files, which IME have issues. Windows has issues period, but you get less using the M$ native compiler, headers and libs.

      *However* if you had read my post properly you would have noted that the minimum flags case includes -DWIN32 which you fail to do......if I leave it out it chokes as we will be trying to compile non win32 code (well skipping the kludges - or whatever). The errors are slightly different but I suggest it might work if you add that define.

        I DID read your post

        Thanks :-) now I know -DWIN32 is important

        C:\>bcc32 -tWD -DWIN32 -I"c:\perl\lib\CORE" -L"C:\borland\bcc55\lib" + C:\perl\ lib\CORE\perl58.lib C:\borland\bcc55\lib\import32.lib C:\borland\bcc55 +\lib\cw32m ti.lib perl_inc.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland perl_inc.c: Warning W8070 perl_inc.c 14: Function should return a value in functio +n main Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland C:\>
        But you didnt say anywhere in your post that this was a problem you just added it silently ;-)
        # Essentially we pass all the same -D defines that perl was built with + plus # the include dir to find the perl headers and the perl56.lib binary w +hich is # what where the real functions defined in the headers are found and w +hat we # will be linking against........
        And this is what I did. There is no -DWIN32 in: perl -MExtUtils::Embed -e ccopts -e ldopts Which is what everyone was saying Nalina use. I personally dont think that it is possible for everyone to use cl.exe

        ps Please stop down voting me now. I was only trying to help. There was no malice.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385348]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2023-05-31 15:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found