Learning C and Learning Make/Configure/Building/Linking

H

Hal Vaughan

I have a problem with port forwarding and I have been working on it for over
2 weeks with no luck. I have found C programs that almost work and Java
programs that almost work, but nothing that does what I need. I've even
tried writing a port forwarder in Java and found problems that nobody seems
to have the answer to in forums. I need to make it work essentially the
same on both Windows and Linux.

There is one program, in C, that comes close to what I need. It is
compilable and even has binaries for Windows. The problem is it does not
have static binaries for Linux. Now, please, before someone starts saying,
"Go away. It's a Linux problem, as in Linux forums," first, I have asked
questions there and received almost no responses. Second, at this point,
my questions are more focused on C than on an OS. (I think that's why I
didn't get help in Linux forums -- it's more a C question.)

Basically what I need to do is to either be able to create static binaries
for Linux or find a way to make sure I can keep the libraries it is
compiled with available (the program would always be run from a CD) so it
can be somehow forced to use them instead of the regular system libraries.

I think my best bet is static binaries.

I've been programming in Perl and Java for 4-5 years now (all self taught).
It looks like the only solution left for me is to learn enough about C and
building C programs to do it myself. I've read a bit of C before and can
often follow the logic of C source code. But the books I've read had very
little on the ./configure && make && make install process, which is what I
think I need now.

How hard is it to learn the process in building a program?

How hard is it to make sure a program is built with static libraries in
stead of shared object libraries?

Is it possible to learn enough of this to be able to build a static binary
in a few days or a week?

And, lastly, what books or links would people recommend for this?

Thanks for any help on this.

Hal
 
B

Ben Pfaff

Hal Vaughan said:
There is one program, in C, that comes close to what I need. It is
compilable and even has binaries for Windows. The problem is it does not
have static binaries for Linux. Now, please, before someone starts saying,
"Go away. It's a Linux problem, as in Linux forums," first, I have asked
questions there and received almost no responses. Second, at this point,
my questions are more focused on C than on an OS. (I think that's why I
didn't get help in Linux forums -- it's more a C question.)

It really is a Linux problem. It is easy to change the link step
of a program build to use static libraries. You should be able
to figure it out, in fact, from the C compiler documentation.
 
H

Hal Vaughan

Ben said:
It really is a Linux problem.

As I said, yes, I see that. The problem is I've been working on this thing
for 2 weeks, going on about 5 hrs sleep a night with this and other coding
that must be done, and what I need is help. The Linux forums are low
traffic and don't seem to have people who can help.
It is easy to change the link step
of a program build to use static libraries. You should be able
to figure it out, in fact, from the C compiler documentation.

Even if it uses make? This program has a configure file that is over 24,000
lines long and a huge make file. I've tried going through them to find out
what to change. With your suggestion I'll start checking compiler (gcc)
docs.

Thanks, even for a small pointer. To be honest (and not to be judgmental),
it is more help than I've ever gotten on any C forums before this.

Hal
 
S

Skarmander

Hal said:
I have a problem with port forwarding and I have been working on it for over
2 weeks with no luck. I have found C programs that almost work and Java
programs that almost work, but nothing that does what I need. I've even
tried writing a port forwarder in Java and found problems that nobody seems
to have the answer to in forums. I need to make it work essentially the
same on both Windows and Linux.

There is one program, in C, that comes close to what I need. It is
compilable and even has binaries for Windows. The problem is it does not
have static binaries for Linux. Now, please, before someone starts saying,
"Go away. It's a Linux problem, as in Linux forums," first, I have asked
questions there and received almost no responses. Second, at this point,
my questions are more focused on C than on an OS. (I think that's why I
didn't get help in Linux forums -- it's more a C question.)
Like Ben Pfaff said: nope, it really isn't. It a compilation environment
question, but not a language question.
Basically what I need to do is to either be able to create static binaries
for Linux or find a way to make sure I can keep the libraries it is
compiled with available (the program would always be run from a CD) so it
can be somehow forced to use them instead of the regular system libraries.

I think my best bet is static binaries.
Yes, if you intend to run the program from a live system with different
library versions you'll need to link statically. If you can boot from the CD
and set up your own environment, you can of course arrange dynamic linking
from there.
I've been programming in Perl and Java for 4-5 years now (all self taught).
It looks like the only solution left for me is to learn enough about C and
building C programs to do it myself. I've read a bit of C before and can
often follow the logic of C source code. But the books I've read had very
little on the ./configure && make && make install process, which is what I
think I need now.
Then you don't really want to learn C, per se. You're talking the standard
Unix build process. Try a good book on Unix or GCC. (Sorry, I don't have any
reading tips handy; I'm mostly self-taught too. :)
How hard is it to learn the process in building a program?
If you're designing the process, pretty easy. Make is quite basic.

If not, arbitrarily hard. Some programs have build processes nobody really
understands. I'm not kidding. Make plus shell scripts give you unlimited
potential for shooting yourself in the foot, arm, leg, head and still have
enough ammo left to finish Quake on nightmare level.
How hard is it to make sure a program is built with static libraries in
stead of shared object libraries?
Depends. If the program is designed to work with dynamic libraries (using
dlopen() and friends), it's obviously impossible without modifying the
source. But this would be rare.

For a total idiot's approach, try 'env CFLAGS="${CFLAGS} -static" make'. If
you're lucky, this may actually produce static binaries. If not, you'll need
to delve into the makefile. Good luck.

S.
 
H

Hal Vaughan

Skarmander said:
Like Ben Pfaff said: nope, it really isn't. It a compilation environment
question, but not a language question.

Just your wording of compilation environment is a big help.  I've worked
heavily in Java and Perl, and such a thing is not an issue with those
languages, so to try to get a handle on something like that is rather
difficult and having the problem or issue labeled specifically is a huge
help.
Yes, if you intend to run the program from a live system with different
library versions you'll need to link statically. If you can boot from the
CD and set up your own environment, you can of course arrange dynamic
linking from there.

That's what I'm hoping to do.  I figured static, but this is so unfamiliar
to me even having that confirmed is a big help.
Then you don't really want to learn C, per se. You're talking the standard
Unix build process. Try a good book on Unix or GCC. (Sorry, I don't have
any reading tips handy; I'm mostly self-taught too. :)

No tips, but, again, giving me name, such as your phrase "the standard Unix
build process" helps a clueless newbie like me to identify more about where
to look for an answer.  It seems small, but I've gotten so many, "Sorry,
not here, go elsewhere" answers in forums that have proved helpless, I've
begun to wonder why the posters even bothered.  They're not helping anyone,
other than telling me to get lost, and, while it is clear they know a lot
more about the situation than I do, aren't even offering enough to help a
newbie figure out where specifically to look.  It's almost as if there's a
lot of people who get off on saying, "Sorry, we can't help you and we don't
care enough to even help you find where to look."
If you're designing the process, pretty easy. Make is quite basic.

If not, arbitrarily hard. Some programs have build processes nobody really
understands. I'm not kidding. Make plus shell scripts give you unlimited
potential for shooting yourself in the foot, arm, leg, head and still have
enough ammo left to finish Quake on nightmare level.

I can understand that.  Unfortunately, I'm working with someone else's code,
and the programmer himself, while on a mailing list, is about as helpful as
a brick to a drowning man.
Depends. If the program is designed to work with dynamic libraries (using
dlopen() and friends), it's obviously impossible without modifying the
source. But this would be rare.

For a total idiot's approach, try 'env CFLAGS="${CFLAGS} -static" make'.
If you're lucky, this may actually produce static binaries. If not, you'll
need to delve into the makefile. Good luck.

Thanks.  I'll see what that does.

While you may not have been able to give me but one or two specific
suggestions, thank you for the effort.  It speaks well of you that when I
said I was new and didn't know what to, instead of just telling me to fsck
off, you made the effort to provide me with help by naming the process or
situation and giving me a concrete area of what to look for or to work
with, rather than just an RTFM -- which, for someone who has been working
on this for a while and not made any headway is frustrating.

Thank you.

Hal
 
W

William Ahern

I have a problem with port forwarding and I have been working on it for over
2 weeks with no luck. I have found C programs that almost work and Java
programs that almost work, but nothing that does what I need. I've even
tried writing a port forwarder in Java and found problems that nobody seems
to have the answer to in forums. I need to make it work essentially the
same on both Windows and Linux.

This is the wrong forum. For Unix programming questions try
comp.unix.programmer; comp.os.linux.development.apps might be
useful too (though, the technical specificity is often lacking, if you're
questions are about build processes for GNU autotools or other
GNU/Linux non-programming stuff you might get quicker help). You'll get
much more help in the right forum, and often wrong answers in the wrong
forum.

Also, next time round be more specific. People can't answer broad
questions and general personal statements. You say "port forwarding", and
I still don't have any idea what you want or what you're trying to
accomplish (often two different things). Maybe a Cisco router will help,
or information on packet filter configuration.

- Bill
 
K

Keith Thompson

Hal Vaughan said:
Ben Pfaff wrote: [...]
It is easy to change the link step
of a program build to use static libraries. You should be able
to figure it out, in fact, from the C compiler documentation.

Even if it uses make? This program has a configure file that is over 24,000
lines long and a huge make file. I've tried going through them to find out
what to change. With your suggestion I'll start checking compiler (gcc)
docs.

You might also try comp.unix.programmer (your situation sounds like it
could probably apply to any Unix-like system) and/or gnu.gcc.help.
comp.unix.programmer is fairly active; I sometimes hang out there
myself.

If the configure file is 24,000 lines long, it's unlikely that either
it or the make file is hand-written. Find out what they were
generated from. <OT><HINT>GNU autoconf</HINT></OT>
 
L

liljencrantz

Hal Vaughan skrev:
Just your wording of compilation environment is a big help. I've worked
heavily in Java and Perl, and such a thing is not an issue with those
languages, so to try to get a handle on something like that is rather
difficult and having the problem or issue labeled specifically is a huge
help.


That's what I'm hoping to do. I figured static, but this is so unfamiliar
to me even having that confirmed is a big help.


No tips, but, again, giving me name, such as your phrase "the standard Unix
build process" helps a clueless newbie like me to identify more about where
to look for an answer. It seems small, but I've gotten so many, "Sorry,
not here, go elsewhere" answers in forums that have proved helpless, I've
begun to wonder why the posters even bothered. They're not helping anyone,
other than telling me to get lost, and, while it is clear they know a lot
more about the situation than I do, aren't even offering enough to help a
newbie figure out where specifically to look. It's almost as if there's a
lot of people who get off on saying, "Sorry, we can't help you and we don't
care enough to even help you find where to look."


I can understand that. Unfortunately, I'm working with someone else's code,
and the programmer himself, while on a mailing list, is about as helpful as
a brick to a drowning man.


Thanks. I'll see what that does.

While you may not have been able to give me but one or two specific
suggestions, thank you for the effort. It speaks well of you that when I
said I was new and didn't know what to, instead of just telling me to fsck
off, you made the effort to provide me with help by naming the process or
situation and giving me a concrete area of what to look for or to work
with, rather than just an RTFM -- which, for someone who has been working
on this for a while and not made any headway is frustrating.

Thank you.

A couple of pointers:

1). Check if there is a file called Makefile.am. If you find it, the
software you are using uses Automake. Good luck. You'll need it.

1). Check if there is a file called either 'configure.ac' or
'configure.in' somewhere in the directory tree. If you find it, that
means the software you are using uses Autoconf. Do not try to
understand the 'configure' file, learn a bit about Autoconf and try
reading 'configure.ac' or 'configure.in'. The Autoconf manual:
http://www.gnu.org/software/autoconf/manual/autoconf-2.57/html_mono/autoconf.html,
a tutorial: http://roo.no-ip.org/howtos/autoconf.php.

2). Linkers produce static binaries by default. If the software
currently uses dynamic linking, you should be able to find the specific
switches, e.g. by searching for '-Bdirect'. Try reading the manual for
the 'ld' command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top