views:

550

answers:

2

I understand that boost regex static library is created with the ar utility by archiving the individual object files.

I linked boost regex library by using the -l option in gcc. This worked very well.

g++ *.o libboost_regex-gcc-1_37.a -o sairay.out

I individually compiled the boost regex source files and then tried to link the object files of my application and the object files of boost regex into a single executable. But now I am getting errors.

  g++ *.o -o sairay.out
  Undefined                       first referenced
  symbol                             in file
  main                                /opt/csw/gcc3/lib/gcc/sparc-sun-solaris2.8/3.4.5/crt1.o

I wish to know what is the difference between linking the static library and linking the individual objects of the static library files with the applicatiion?

A: 

You apparently forgot to include the object file of your application which defines the main function. Maybe you typed g++ myapp.cpp instead of g++ -c myapp.cpp (to actually create an object file instead of a ready linked binary already) ?

A static library really is not much more than just an archive of many or few object files (archived by the ar utility) with a symbol table index attached for quick lookups. So if you include the object files manually in the link i think it's doing essentially the same.

Try the following to view the object files it contains

ar tv libboost_regex-gcc-1_37.a
Johannes Schaub - litb
+1  A: 

I think it's supposed to be:

g++ *.o -L. -lboost_regex-gcc -o sairay.out -static
sfossen