Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Perl & borland 5.5 C/C++ Compiler

by Nalina (Monk)
on Aug 24, 2004 at 06:59 UTC ( [id://385343] : perlquestion . print w/replies, xml ) Need Help??

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

Hey monks,

As per ur suggestions to my earlier thread 'embed perl in C', I installed free Borland 5.5 C/C++ compiler. I copied 'extern.h' & 'perl.h' header files from 'C:\perl\Lib\Core' to 'C:\borland\BCC5\include' directory. My perl embedded C code is
#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); }
When I compiled this program I got the following errors
E:\>bcc32 perl_inc.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland perl_inc.c: Error E2209 c:\Borland\Bcc55\include\perl.h 37: Unable to open include + file 'config.h' Error E2209 c:\Borland\Bcc55\include\perl.h 475: Unable to open includ +e file 'embed.h' Error E2209 c:\Borland\Bcc55\include\perl.h 490: Unable to open includ +e file 'strings.h' Error E2257 c:\Borland\Bcc55\include\perl.h 1078: , expected Error E2257 c:\Borland\Bcc55\include\perl.h 1079: , expected Error E2257 c:\Borland\Bcc55\include\perl.h 1271: , expected Error E2257 c:\Borland\Bcc55\include\perl.h 1751: , expected Error E2209 c:\Borland\Bcc55\include\perl.h 1807: Unable to open inclu +de file 'handy.h' Error E2209 c:\Borland\Bcc55\include\perl.h 1971: Unable to open inclu +de file 'unixish.h' Error E2139 c:\Borland\Bcc55\include\perl.h 2287: Declaration missing +; Error E2139 c:\Borland\Bcc55\include\perl.h 2288: Declaration missing +; Error E2139 c:\Borland\Bcc55\include\perl.h 2290: Declaration missing +; Error E2293 c:\Borland\Bcc55\include\perl.h 2302: ) expected Error E2209 c:\Borland\Bcc55\include\perl.h 2325: Unable to open inclu +de file 'iperlsys.h' Fatal F1003 c:\Borland\Bcc55\include\regexp.h 18: Error directive: Mus +t use C++ for REGEXP.H *** 15 errors in Compile ***
Then I just copied all the required header files(only those which are not found in borland include folder) from 'C:\perl\lib\core' directory to 'c:\borland\bcc5\include' directory.

After copying I still am getting errors like
E:\>bcc32 perl_inc.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland perl_inc.c: Error E2303 c:\Borland\Bcc55\include\win32.h 314: Type name expected Error E2293 c:\Borland\Bcc55\include\win32.h 413: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 105: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 106: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 108: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 110: ) expected Error E2141 c:\Borland\Bcc55\include\perlio.h 111: Declaration syntax +error Error E2293 c:\Borland\Bcc55\include\perlio.h 112: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 214: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 227: ) expected Error E2303 c:\Borland\Bcc55\include\perlio.h 339: Type name expected Error E2303 c:\Borland\Bcc55\include\perlio.h 342: Type name expected Error E2293 c:\Borland\Bcc55\include\perlio.h 345: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 354: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 358: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 365: ) expected Error E2293 c:\Borland\Bcc55\include\perlio.h 370: ) expected Error E2303 c:\Borland\Bcc55\include\win32iop.h 73: Type name expected Error E2303 c:\Borland\Bcc55\include\win32iop.h 74: Type name expected Error E2303 c:\Borland\Bcc55\include\win32iop.h 77: Type name expected Error E2303 c:\Borland\Bcc55\include\win32iop.h 133: Type name expecte +d Error E2238 c:\Borland\Bcc55\include\perl.h 1775: Multiple declaration + for 'AV' Warning W8017 c:\Borland\Bcc55\include\dosish.h 137: Redefinition of ' +Stat' is not identical Error E2257 c:\Borland\Bcc55\include\perl.h 2075: , expected Error E2257 c:\Borland\Bcc55\include\perl.h 2076: , expected Error E2257 c:\Borland\Bcc55\include\perl.h 2077: , expected Error E2228 c:\Borland\Bcc55\include\perl.h 2077: Too many error or wa +rning messages *** 26 errors in Compile ***
Can I use borland C/C++ compiler for embedding perl in to C? If I can not which compiler(freeware) should I use for this purpose?

Is there any other way I can embed perl script in to C & C in to perl?

Thanks in advance

Replies are listed 'Best First'.
Re: Perl & borland 5.5 C/C++ Compiler
by tachyon (Chancellor) on Aug 24, 2004 at 07:50 UTC

    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\wsock32.li +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:\>

    cheers

    tachyon

      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.

Re: Perl & borland 5.5 C/C++ Compiler
by blm (Hermit) on Aug 24, 2004 at 07:20 UTC

    May I suggest for next time that you don't copy the headers you add the 'C:\perl\lib\core' to the commandline. There should be a commandline switch for bcc32 to add directories for the compiler to find .h files not in the standard include directory 'c:\Borland\Bcc55\include\'.

    From here

    To add include directories,
    you need to specify   -I"<directory>;<directory>."
    Update: Take care of wordwrap between the dash and the I and fix the link.