Topic: problem linking static labraries

Problem linking static libraries

Adding two new libraries to my project following messages appears after build:

Generating CASTOR12lt.exe
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLib_panels

c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llib_CastorWeight
collect2.exe: error: ld returned 1 exit status

Error(E42): Last command making (CASTOR12lt.exe) returned a bad status
Error(E02): Make execution terminated

However Lib_panels.a and lib_CastorWeight.a are properly built in there own directories and the directories are in the search directories of the option tab file locations available under Library Directories like all other lib's.

The linker in the compiler flag tab is as follows:
-lASC12 -lstructure_concept -ledit-sheet-library -lDXF_interface -llongit_str_check -lLib_panels -llib_CastorWeight

All prior lib's are linked properly; thy are all static 64 bits

What is going wrong and how can I fix this problem?

An other question:
I found that i have to rebuild the main program (compiling all source files of the main program again) after source of libraries are changed. Is there  a way to avoid this?

Re: problem linking static labraries


Using the -l flag normally means the library name following the flag is prefixed with "lib" during the file search.  In your example, the linker would be looking for files named libLib_panels.a and liblib_CastorWeight.a.  I would strongly recommend that you name those libraries simply libpanels.a and libCastorWeight.a just to conform to what the linker expects, and change the flags to -lpanels -lCastorWeight.  I think the linker should work after that change, but perhaps I'm incorrect.

Simply Fortran doesn't consider the time stamps of libraries referenced by the -l flag when determining whether or not to rebuild the executable.  You need to Clean and Build each time because it doesn't know that the libraries changed.  If the libraries were directly added to the project rather than referenced via flags, which is not recommended, it would actually rebuild just the executable properly (but other issues would be introduced).

You can instead just delete the executable in Windows Explorer instead.  If you first do that and then request a build in your main executable project, it will simply re-link using the updated libraries.  It isn't ideal, but it might be significantly faster depending on the complexity of your main executable project.

I think that Simply Fortran could, in fact, check for time stamps on referenced libraries, although it might be tricky to implement.  I'll have to look into it.

Let us all know if changing the library names work for your linking issue.

Jeff Armstrong
Approximatrix, LLC

Re: problem linking static labraries

thanks Jeff,
Problem with library names is solved!
The 2nd question regarding rebuilding after changed lib source is nasty but still to do in this way. In general one should test a Library prior to linking to a main program but in my case it is not so easy (see the CVF history) and needs more effort than test it by the main program.