Search code examples
c++perlheader-files

Execute C++ program from Perl script; does it require a compiler?


I have a somewhat more complicated question this time. I have written a short Perl program where my final ouput is in an array. I want to execute a C++ script with a .hpp file extension within my Perl script on each element of my output (I have downloaded the source code from the UCSC Genome Browser). This is really difficult for me since I'm a beginner in programming overall and don't know anything about C++. I've done some reading and I think the best for me would be to use a qx call. I've tried that and it just opens the .hpp file in the text editor when I run my Perl script. I'm not sure if this is because I've erroneoulsy assigned the .hpp file extension to be opened with Editor or whether I need a compiler to run .hpp files in general.

my $info = qx(primercheck.hpp);
print "primercheck.hpp is: $info\n";

Solution

  • An .hpp file is a header file, that generally contains just macros and declarations, not executable code. It is used to specify the interface to code in .cpp files and cannot be compiled on its own.

    A typical C++ program consists of several .cpp and .hpp files that must be compiled in combination and then linked with each other and with library files to create an executable image.

    So yes, you do need a compiler, and a lot more besides!