[LCP] How to do intremental linking with gcc and ld

Mike or Penny Novack stepbystepfarm at mtdata.com
Sat Jun 20 21:04:44 EST 2009


Bryan Christ wrote:

>I have a top-level directory from which I want to share as common code
>with two different applications (a client and a server).  I thought it
>would be quite easy to create a combined object file in the common
>directory and then link to it from each of the individual programs.
>While I don't have any problem compiling the larger common object
>file, I have having unresolved symbols when I try to link the two
>different programs to it.
>
>Here is how I am creating the common object file:
>
> gcc -c $(CFLAGS) $(INCLUDES) $(DEFS) *.c
> ld -r -o common_tools.o *.o
>
>And here is how I try to link against the common object file:
>
>gcc -c $(CFLAGS) $(INCLUDES) $(LIBS) $(NORMAL_DEFS) *.c
>ld -o myprogram *.o ../../common/common_tools.o
>
>I'm sure I'm missing something trivial but don't know what that is.
>
>Thank in advance to anyone who helps.
>
>  
>
I will be paying attention to this one as it's something I used to do 
with other compilers and link editors all the time. While I can't help 
directly with an answer, I have a question which might prove useful.

Bryan, you say you have some unresolved symbols errors but don't tell us 
at what stage. Now back in my working days (IBM mainframe) until the 
entire load module (executable) had been linked together would be 
specifying "LET" on the partial links. In other words, would expect that 
there would still be some references that wouldn't be resolved until the 
whole "static link" was put together. What a "link editor" does.

Michael

-- 
There is no possibility of social justice on a dead planet except the equality of the grave.




More information about the linuxCprogramming mailing list