简体   繁体   中英

How can I check for a C++ compiler in Makefile.PL?

在Perl模块/发行版/包中,如何测试“Makefile.PL”中是否存在正常运行的C ++编译器,如果C ++编译器不能正常工作则停止?

ExtUtils::CppGuess was written for exactly this purpose. It's not perfect, but will work on most common platforms.

you could do what autoconfig does as described here . They look for the shell variable CXX then CCC then the binary g++ in the path then c++ in the path. One they do not test for is clang++ or microsoft's compilers, but this functionality could be easily duplicated in perl.

    @path = split(/:/, $ENV{"PATH"} );
    $CXX = $ENV{"CXX"} || $ENV{"CCC"} || undef;
    if (!defined($CXX)){
            foreach my $path(reverse(@path)){
                    my $test = $path . "/g++";
                    if ( -e $test){
                            $CXX = $test ;
                            break;
                    }
            }
    }
    print $CXX . "\n"

If other compilers need to be looked for, you could easily modify the code to test for them as well by adding aditional if statements. Aditionally if you wanted to search places other than the the system PATH , you could append possible directories to @path .

I would second Mohit Jain's comment in recommending the use of grep to find a compiler. You'd have to be careful to get as few false positives/negatives as possible, but it should be doable. The specific implementation of this would change based on your environment, of course.

Of course, if you are looking for a specific compiler you can check for files and such specific to that compiler, but judging by the lack of such details in your question you appear to be looking for a more general solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM