ron
ron

Reputation: 995

problem with ar, linking and undefined reference

I have a software package consisting of some 500+ fortran .f files. It is rather well organized into various subfolders, and there is one high level compile script which calls the various Makefile's within the subfolders.

Using the PGI compiler, I am doing this on SLES 11.4 x86_64.

There are no compile errors.

The problem happens at the end, when linking trying to create the one executable file the result is the same 10 or so undefined references to various functions. I have explored all the Makefile(s) and there are no missing statements in there, and for the stated undefined references their respective .o file is present within the objects/ folder and I also recognize all those .o files are being used in the creation of the .a file.

There is a total of 3 .a files created during the entire compile, and after 50 or so of the however many .f files are compiled there is an Updating whatever#.a printed where a subsequent running of ar happens. This happens many times for each of the whatever1.a and whatever2.a and whatever3.a over the duration of the compile.

Thing is, knowing there is no error within the Makefile best I can tell, I can trigger a recompile of just one .f which corresponds to one of the undefined references and when that whatever#.a file is updated and linked that specific undefined reference goes away. So I tried doing this for the others and sometimes it works but some it does not, it almost seems by chance I was able to fix it this way for some of the undefined references.

The other major thing is with all object .o files created, if I simply remove all 3 .a files and run the compile script then only the ar happens to recreate those 3 .a. files followed by the final linking which then says a whole slew of different undefined references.

I believe the problem lies with the usage of ar of possibly the version of it and/or the operating system is bugged. Anybody know the real cause and how to get around this? I am thinking of modifying the compile script instead of linking with 3 .a files to just manually cause the linking with all the ~500 .o files and take ar out of this completely.

Is there some limit to the number of .o files that can be put into a .a file with .ar ?

Upvotes: 0

Views: 918

Answers (1)

ron
ron

Reputation: 995

got my source files to link finally. The solution was to work from last to first for the order that the undefined references were printed...

I would go to that /objects/whatever/ subfolder where those specific .o files resided that the undefined reference complained about.

I simply removed those .o files, then reran my compile script which calls a Makefile and it only recompiled those .f files and then did an ar r of those files into the existing .a library. Then those specific undefined references disappeared. I repeated this for the 10 to 15 undefined references that had initially emerged, eventually reaching success.

Doing ar -s or ranlib on the existing .a files did not help. So I guess it was an order of compilation and include into the .a file that was the problem? Because I know initially that all necessary .o files were in the three .a files.

Upvotes: 1

Related Questions