Linking to Static Libraries
Posted: Tue Oct 09, 2012 10:06 pm
When you try to link to a static library, you will often get a lot of undefined references
Methodology to resolve the problem
1) Add an Import to the library your linking to
2) Add any Imports to know dependencies
3) Add Imports directly below the first import statement for a library that's reported an error eg undefined refference to foo ... first appears in libfoo
4) Add the functions to the library your linking to
Additionally some libraries may have multiple definitions and may still have unresolved symbols
Add these to the top
Methodology to resolve the problem
1) Add an Import to the library your linking to
Code: Select all
ImportC "libbar.a" : EndImport
Code: Select all
ImportC "libbar.a" : EndImport
ImportC "-lstdc++" : EndImport ;<------
Code: Select all
ImportC "libbar.a" : EndImport
ImportC "-libfoo" : EndImport ; <------
ImportC "-lstdc++" : EndImport
4) Add the functions to the library your linking to
Code: Select all
ImportC "libbar.a" : EndImport
ImportC "-libfoo" : EndImport
ImportC "-lstdc++" : EndImport
ImportC "libbar.a" ;<------
foo()
bar()
EndImport
Add these to the top
Code: Select all
ImportC "-Wl,--allow-multiple-definition" : EndImport
ImportC "-Wl,--unresolved-symbols=ignore-in-object-files" : EndImport ;use as a last resort
ImportC "-libfoo" : EndImport
ImportC "-lstdc++" : EndImport
ImportC "libbar.a"
foo()
bar()
EndImport