tags:

views:

57

answers:

1

Hi everybody,

I am little new to MAC os but while building an cpp application on MAC OS X , using g++ I am getting strange error from linker.

first at one step I am creating a library using several object files generated from cpp source and then I am creating a single archive using ar rvs command.

If I am linking this library to another cpp application which is using some of the classes provided by the library , it fails to fetch some of the symbols at linking and throws undefined symbol error.

I know and I am able to see those symbols in library using nm. and signature and string matches exactly they way its in .a file.

there are many other symbols , this library is providing and getting recognized at link time.

option used for linking are

      g++-framework IOKit -framework Carbon -L <> -l<lib>-L -l<lib> -o exe ./obj.o

and other are several paths for other libs using -L

I am not an expert on MAC, however any suggestion from members would be appreciable.

Thank in advance

-brij

A: 

You need to put the object files (obj.o) before the libraries when linking.

The reason for this is that when processing the objects, the linker keeps a list of the undefined symbols. When it processes a library, it adds any currently undefined symbols it finds in the library (technically, it works on the level of objects in the library). By putting the libraries first, no symbols are undefined when they are processed, so no objects from the library get added.

KeithB