Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Error "Compilation failed in require" with "use" syntax

by SuzuBell (Acolyte)
on Sep 16, 2013 at 02:46 UTC ( #1054210=perlquestion: print w/ replies, xml ) Need Help??
SuzuBell has asked for the wisdom of the Perl Monks concerning the following question:

I recently asked this on stackoverflow.com, and nobody could figure it out.

I am using Perl in Eclipse. In the same directory, I have one .pl file and two .pm files (pmFile1.pm, pmFile2.pm). At the top of the .pl file, I use the command:

use pmFile1; use pmFile2;

I get an error: "Compilation failed in require". This is the entire warning. When I type into command line the following command:

perl -Mlib=/Desktop/code -e'use pmFile1;'

I get the following warning in my terminal: "syntax error at -e line 1, near "use pmFile1." Execution of -e aborted due to compilation errors"

I also tried right-clicking on the project directory in Project Explorer, selecting "Properties", selecting "Perl Include Path", and then adding the directory that contains the two files. Still, even after restarting Eclipse, and checking that the directory path is still there, the error remains.

I would be grateful to hear any advice on this! I have been stumped for days. Thank you.

Comment on Error "Compilation failed in require" with "use" syntax
Select or Download Code
Re: Error "Compilation failed in require" with "use" syntax (eclipse ide)
by Anonymous Monk on Sep 16, 2013 at 02:55 UTC

    I get an error: "Compilation failed in require". This is the entire warning

    I can't help you with eclipse , much, except to say this is surely a FAQ item (its @INC path management, its perl-faq)

    One way to manage is File::FindLib or lib+FindBin

    Absolute paths always work, you can even do the same thing using the shebang

    #!/usr/bin/perl -I/hardcoded/paths -I/and/another --

    Now to your shell attempt you've got typo

    syntax error at -e line 1, near "use pmFile1." ^ ^ ^ ^
    that is a comma not a semicolon;
    $ perl -e " use strict. " syntax error at -e line 1, near "use strict." Execution of -e aborted due to compilation errors.

    Generic advice :) On debugging, verify everything, talk to teddybear ... checklists and more

      Thanks for your input.

      When you say: "its @INC path management"; I do not feel too confident working in the terminal. I do not have much experience working with these libraries and such. Is there anything I can do in Eclipse to solve this issue? The strange this is I believe this script was working earlier. I do not know what changed or how to determine that, and how this all relates to INC path management.

      Thanks.

        Is there anything I can do in Eclipse to solve this issue?

        Change the shebang like I showed, it will work with every perl, regardless of where its embedded

        ...

        perlrun#-Idirectory, perlvar#@INC, require, use

Re: Error "Compilation failed in require" with "use" syntax
by kcott (Abbot) on Sep 16, 2013 at 04:23 UTC

    G'day SuzuBell,

    I'm not familiar with Eclipse. I can't you help you with that; however, the problem may not be related to Eclipse.

    Your script error "Compilation failed in require" is described in perldiag: as you can see, this is a generic message. I recommend you always use the warnings pragma: use warnings; near the top of your scripts; perl ... -Mwarnings ... -e '...' on the command line. Without knowing what the problem is, I can't tell whether this will provide a more specific message in this instance.

    Assuming you're confident that the path to these modules is correctly set up, check that the user running the script has read access to both files.

    Next, you should check that the package namespace is correct in both modules and that each module returns a TRUE value (usually just 1; on the last line). They should start and end like this:

    package pmFile1; ... 1;
    package pmFile2; ... 1;

    For your command line example, there's a discrepancy between the code you show ('use pmFile1;' [has ";"]) and the error message you show ("use pmFile1." [has "."]). Perhaps that was just a typo. It's best to actually copy and paste code and output, and put both between <code>...</code> tags. That way, we see a verbatim copy of what you're seeing.

    -- Ken

      Thanks Ken. Sorry for a slow reply.

      1) I added the use warnings;

      2) I checked that the user (me) has read access to both files (At least, I right-clicked on their icon in Package Explorer of Eclipse, and saw that all three groups - Owner, Group, Other - had "Read" checked)

      3) I do not know how to check the package namespace is correct in both files. I tried typing "package pmFile1;" into command line terminal but did not get a return value of 1. (I do not use terminal and command line much, I am sorry.) Could you tell me more specifically how I can check this?

      Thanks again

        You seem to have very limited knowledge about your operating system and Perl. I suggest you look at the following:

        "3) I do not know how to check the package namespace is correct in both files."

        Just look at the code.

        -- Ken

Re: Error "Compilation failed in require" with "use" syntax
by boftx (Chaplain) on Sep 16, 2013 at 06:08 UTC
    perl -c is your friend in cases like this. Run that against your .pl file and both .pm files and you'll probably find the error.
      Thanks for the advice, but this is all I get:
      perl -c test.pl
      Switch will be removed from the Perl core distribution in the next major release. Please install it from CPAN. It is being used at pmFile1.pm, line 7393. test.pl syntax OK
      perl -c pmFile1.pm
      pmFile1.pm syntax OK
      perl -c pmFile2.pm
      pmFile2.pm syntax OK
Re: Error "Compilation failed in require" with "use" syntax
by marinersk (Chaplain) on Sep 16, 2013 at 08:09 UTC
    To isolate whether or not Eclipse is part of the problem, I'd pay the toll and try to run the script from the command line.

    If it gets the same error, Eclipse is not your issue.

      I did just that. I posted the command line error in my original post too. Thanks.
Re: Error "Compilation failed in require" with "use" syntax
by sundialsvc4 (Monsignor) on Sep 16, 2013 at 14:28 UTC

    In this case, I can tell you definitively, Eclipse is not part of the problem:   you should be able to execute that command on the command-line and get identical results.

    When Perl encounters a use (or require) statement, it might subsequently do a lot of compiling, as it processes not only these modules but all of their direct and indirect dependencies.   A syntax-error anywhere can produce this result, with or without Eclipse or any other IDE.

    If you do not get identical results, check your local PERL5LIB and other settings to make sure that they really are identical to those that are established in the relevant (Eclipse ...) settings.   You can be quite sure that you will find some discrepancy there.

      Would the error I got from what I wrote in the command line, ie.
      perl -Mlib=/Desktop/code -e'use pmFile1;'
      be considered a syntax problem? I checked the code, I do not see any other red error logos in Eclipse. Thanks...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1054210]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-08-30 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls