Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

How to link multiple object files to get a library file

hamid3252
Beginner
383 Views
Hi friends,

I have compiled some C++ files in Linux, and so I have the object files ready. But my goal is to link them into a library file (like a DLL or LIB file in windows). In windows I did it via VS2008 and by creating a library-type project. But in linux, I have no idea how I can do it via command lines. I am using intel C++ V11.1 (x64). Please help me solve the problem.
Thank you,
Hamidreza,
0 Kudos
2 Replies
aazue
New Contributor I
383 Views
Hi
Easy,
require to use ar and ranlib for create lib.
after you add flag to call lib at instruction compiler.


compiler -c yoursource.c ??.c ??.c ??.c ??.c ext.... (result .o)
ar yourlib.a precedent_result.o (result .a)
ranlib yourlibresult.a (for index)
(after require also your inform path header -I , path Lib -L -l your newlib (flag compiler)

better that you use same compiler two but not obligated
Regards
I forget....
add an dummy link .SO to .a (ln) for after it could be compile as shared
0 Kudos
TimP
Honored Contributor III
383 Views
The stock linux method with ar and ranlib is the one to use with .o files made without -ipo. This is recommended as your first step. The xiar tool which comes with icc is capable of dealing with ipo objects.
0 Kudos
Reply