Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are static c libraries created with one compiler compatible with another?

Tags:

c

gcc

linker

iar

In my case I have a library built with code sourcery gcc targeting arm cortex-m4. I am trying to then link that library into a project being compiled with IAR compiler.

Is it possible to do this or does the library have to be rebuilt with the new tools? What factors affect this?

like image 897
Brandon Yates Avatar asked Oct 08 '13 13:10

Brandon Yates


People also ask

Are static libraries linked?

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

What happens when you link a static library?

Static linking increases the file size of your program, and it may increase the code size in memory if other applications, or other copies of your application, are running on the system. This option forces the linker to place the library procedures your program references into the program's object file.

What is the difference between static library and dynamic library in C?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

How are static libraries used and created?

A static library is a file containing a collection of object files (*.o) that are linked into the program during the linking phase of compilation and are not relevant during runtime. As shown in the diagram above, when a program is compiled, the compiler generates an object file from a source file.


2 Answers

Static library is bundle of several object files which are always compiler specific. So if you try to link a gcc based lib with IAR compiler, you will get error at compile time due to mismatch between object file formats to be linked.

You need to rebuild your library using IAR.

like image 114
Dayal rai Avatar answered Oct 03 '22 12:10

Dayal rai


The IAR compiler for ARM supports the AEABI format, which allows you to compile files with one compiler and link with another.

If you have built your library using GCC and have enabled AEABE, it should be possible to use the static library in a project build using the IAR tools.

like image 27
Lindydancer Avatar answered Oct 03 '22 14:10

Lindydancer