Re: compile Static Link Library

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Dec 01 2010 - 08:47:40 MST

Hi,

When you compile TestNCL.c with "nhlcc -c" (or "gcc -c" for that matter), this will not include all the symbols from the various libraries. This is because "-c" tells the compiler not to run the linker, and hence no extra symbols get linked in.

If you want to combine all the libraries into one big one, you might consider using "ar x" to extract the *.o's from each library,
and then use "ar c" to combine them into one big library. Something like this (which I pulled off the web when googling this topic):

ar -x libabc.a
ar -x libxyz.a
ar -c libaz.a *.o

I haven't tried this, so I don't know if it will work.

Then, you would use:

   gcc main.c -o main -L./ -laz

Pease note that you don't want to use:

   gcc main.c -o main.c ...

as you had below, because you are essentially overwriting your "main.c" file with the compiled executable.

--Mary

On Nov 29, 2010, at 8:27 PM, 柾査乏 wrote:

> Hi, All
> I am a programmer. I face some problems when I want to compile a c-file to Static Link Library.
>
>
>
> Administrator@CSS022:/home/Hans/TestC_NCL/TestNCL>nhlcc -c TestNCL.c -o TestNCL.o
> gcc -DSYSV -D_POSIX_SOURCE -D_XOPEN_SOURCE -DByteSwapped -D__UNIXOS2__ -DNeedFuncProto -ansi -O -Wl,-stack,0x400000 -c TestNCL.c -o TestNCL.o -L/usr/local/lib -I/usr/local/include -I/usr/include -lhlu -lncarg -lncarg_gks -lncarg_c -lXpm -lX11 -lXext -lpng -lz -lg2c -lgcc -lm
> gcc: -stack: linker input file unused because linking not done
> gcc: 0x400000: linker input file unused because linking not done
> gcc: -lhlu: linker input file unused because linking not done
> gcc: -lncarg: linker input file unused because linking not done
> gcc: -lncarg_gks: linker input file unused because linking not done
> gcc: -lncarg_c: linker input file unused because linking not done
> gcc: -lXpm: linker input file unused because link ing not done
> gcc: -lX11: linker input file unused because linking not done
> gcc: -lXext: linker input file unused because linking not done
> gcc: -lpng: linker input file unused because linking not done
> gcc: -lz: linker input file unused because linking not done
> gcc: -lg2c: linker input file unused because linking not done
> gcc: -lgcc: linker input file unused because linking not done
> gcc: -lm: linker input file unused because linking not done
>
>
>
> However, though generate?a TestNCL.o file, ?it couldnt be compiled ?as Static Link Library
> Administrator@CSS022:/home/Hans/TestC_NCL/TestNCL>ar r mylib.lib TestNCL.o
> Administrator@CSS022:/home/Hans/TestC_NCL/TestNCL>ls -l
> Administrator@CSS022:/home/Hans/TestC_NCL/TestNCL>ls -l
> total 13
> -rw-r--r-- 1 Administrator None 2097 Nov 26 11:11 TestNCL.c
> -rw-r--r-- 1 Administrator None 2725 Nov 30 10:58 TestNCL.o
> -rw-r--r-- 1 Administrator None 71 Nov 30 11:25 main.c
> -rw-r--r-- 1 Administrator None 2872 Nov 30 11:18 mylib.lib
>
>
> Administrator@CSS022:/home/Hans/TestC_NCL/TestNCL>gcc main.c -o main.c -static -L. -lmylib
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x42): undefined reference to `_NhlInitialize'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x4e): undefined reference to `_NhlRLCreate'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x53): undefined reference to `_NhlInitialize'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x5f): undefined reference to `_NhlRLCreate'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x69): undefined reference to `_NhlRLClear'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x7a): undefined reference to `_NhlappClass'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0x94): undefined reference to `_NhlCreate'
> ./mylib.lib(TestNCL.o):TestN CL.c:(.text+0x9c): undefined reference to `_NhlRLClear'
> ./mylib.lib(TestNCL.o):TestNCL.c:(.text+0xb4): undefined reference to `_NhlRLSetInteger'
>
> ........
>
>
> How to solve this problem ??
>
> THX
> !!!!!!!!!!!!!!!!!!!!
> Hans Sun
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Dec 1 08:47:49 2010

This archive was generated by hypermail 2.1.8 : Wed Dec 01 2010 - 08:48:58 MST