S
Steve Titus
I am a veteran Perl user, but a newbie embedder. I am trying to figure
out the best way to solve a problem I have. Please read along--any
advice is appreciated.
TASK: I am talking to a networked camera via HTTP, and the URLs I need
to send and the requests I get back are a variety of fairly complicated
and not always consistent text strings. THE GOAL: I need to interface
with the camera from a C/C++ program.
APPROACH: the camera came with a hard-copy manual that spelled out all
the camera params and commands, syntax, etc. I slapped all the info into
a config file in my own white-space-delimited column format that is
pretty simple to read and understand. As far as parsing goes, I figure
there are 4 general approaches I could have taken:
1. Hack something together using sscanf, strtok, and their ilk, and not
have it robust, but get it working quickly. NOT AN OPTION.
2. Do it "right" in C using lex/yacc, bison/flex, etc. I have done
parsers in this manner, but generally takes longer than using a Perl
approach, and you have to debug the grammar corner cases, etc.
3. Embed Perl into the C program and use Perl for all the text munging.
Has the added advantage of being flexible, not having to recompile when
config file changes, yada.
4. Do the config file in standardized text format like XML, and it may
not be too readable to humans, but I am sure there are some free
libraries that will parse it easily and hand me my data in C nicely.
COMMENTS WELCOME on which approach is best...but I chose 3.
Now to the Perl question:
PERL EMBEDDING: I read the manual and got ExtUtils::Embed working just
fine. I created 3 simple classes: perl_hash, perl_array, and
perl_scalar, in C++, and wrote a simple wrapper class that contains the
Perl interpreter and has one method -- call(). You can call any perl
function you like, hand it a C++ perl_array (@_) that you've filled
inside C/C++ and get back a perl_array as a result from call() after it
invokes Perl. It works great, and I was very proud of myself for taking
a general embedding approach that would work in mutliple projects! But....
PROBLEM: the problem is that I just let ExtUtils::Embed spew out all the
compile and link flags that I used for building, and when I run the
executable on another machine, it barfs with different messages about
shared libararies (depending on machine on which it is run), with 2
representative error messages being:
cperltest: error while loading shared libraries: libperl.so: cannot open
shared object file: No such file or directory
cperltest: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required
by cperltest)
QUESTIONS:
I have a basic understanding of what shared libraries are and how they
work, but I am not knowledgable about GLIBC compatibilities, or about
the "best" way to attain the following goal: I want someone to be able
to write a C/C++ program that links against my Cperl library, and as far
as they are concerned, it will just work.
1. Is this possible?
2. Could someone please give me a short primer on the way that GCC build
env, user environment (e.g. LD_LIBRARY_PATH), and Perl environment (how
Perl was built, etc), all influence what the "right" answer is to
solving this problem? All these issues have me confused!
3. What approach should I take? The ground rules are that all the boxes
I am working with will all have basically same O/S -- all Red Hat boxes
that look pretty much like
Linux 2.4.20-19.7smp #1 SMP Tue Jul 15 13:34:04 EDT 2003 i686 unknown
but they may have slightly different Perl versions installed in slightly
different places. SHould I compile everything statically so that my
cperl.a essentially contains a stand-alone Perl? How would I go about
doing this if it's possible?
4. How do you figure out what shared libraries an executable depends on?
5. How do you statically compile an executable (gcc version 3.2.3) so
that it depends on NOTHING?
6. Should I even try to compile statically, or can I somehow keep things
the way they are, and just have everyone add a few things to their
LD_LIBRARY_PATH on my behalf? Any philosophical and pratical help would
be great...
Any and all help is so greatly appreciated! Thanks!
Steve
out the best way to solve a problem I have. Please read along--any
advice is appreciated.
TASK: I am talking to a networked camera via HTTP, and the URLs I need
to send and the requests I get back are a variety of fairly complicated
and not always consistent text strings. THE GOAL: I need to interface
with the camera from a C/C++ program.
APPROACH: the camera came with a hard-copy manual that spelled out all
the camera params and commands, syntax, etc. I slapped all the info into
a config file in my own white-space-delimited column format that is
pretty simple to read and understand. As far as parsing goes, I figure
there are 4 general approaches I could have taken:
1. Hack something together using sscanf, strtok, and their ilk, and not
have it robust, but get it working quickly. NOT AN OPTION.
2. Do it "right" in C using lex/yacc, bison/flex, etc. I have done
parsers in this manner, but generally takes longer than using a Perl
approach, and you have to debug the grammar corner cases, etc.
3. Embed Perl into the C program and use Perl for all the text munging.
Has the added advantage of being flexible, not having to recompile when
config file changes, yada.
4. Do the config file in standardized text format like XML, and it may
not be too readable to humans, but I am sure there are some free
libraries that will parse it easily and hand me my data in C nicely.
COMMENTS WELCOME on which approach is best...but I chose 3.
Now to the Perl question:
PERL EMBEDDING: I read the manual and got ExtUtils::Embed working just
fine. I created 3 simple classes: perl_hash, perl_array, and
perl_scalar, in C++, and wrote a simple wrapper class that contains the
Perl interpreter and has one method -- call(). You can call any perl
function you like, hand it a C++ perl_array (@_) that you've filled
inside C/C++ and get back a perl_array as a result from call() after it
invokes Perl. It works great, and I was very proud of myself for taking
a general embedding approach that would work in mutliple projects! But....
PROBLEM: the problem is that I just let ExtUtils::Embed spew out all the
compile and link flags that I used for building, and when I run the
executable on another machine, it barfs with different messages about
shared libararies (depending on machine on which it is run), with 2
representative error messages being:
cperltest: error while loading shared libraries: libperl.so: cannot open
shared object file: No such file or directory
cperltest: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required
by cperltest)
QUESTIONS:
I have a basic understanding of what shared libraries are and how they
work, but I am not knowledgable about GLIBC compatibilities, or about
the "best" way to attain the following goal: I want someone to be able
to write a C/C++ program that links against my Cperl library, and as far
as they are concerned, it will just work.
1. Is this possible?
2. Could someone please give me a short primer on the way that GCC build
env, user environment (e.g. LD_LIBRARY_PATH), and Perl environment (how
Perl was built, etc), all influence what the "right" answer is to
solving this problem? All these issues have me confused!
3. What approach should I take? The ground rules are that all the boxes
I am working with will all have basically same O/S -- all Red Hat boxes
that look pretty much like
Linux 2.4.20-19.7smp #1 SMP Tue Jul 15 13:34:04 EDT 2003 i686 unknown
but they may have slightly different Perl versions installed in slightly
different places. SHould I compile everything statically so that my
cperl.a essentially contains a stand-alone Perl? How would I go about
doing this if it's possible?
4. How do you figure out what shared libraries an executable depends on?
5. How do you statically compile an executable (gcc version 3.2.3) so
that it depends on NOTHING?
6. Should I even try to compile statically, or can I somehow keep things
the way they are, and just have everyone add a few things to their
LD_LIBRARY_PATH on my behalf? Any philosophical and pratical help would
be great...
Any and all help is so greatly appreciated! Thanks!
Steve