1
votes

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?

2
i'm sorry i've missed your first sentence. but you seem to already understand what is happening. please double check to see that the object file containing your main function is linked too. - Johannes Schaub - litb
I think that you mistyped as you say gcc and -l as compiler/option respectively but that is not reflected in your command. Which is correct in what you are doing? - Suroot

2 Answers

2
votes

I think it's supposed to be:

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

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