Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 01 May 2015 17:13:31 -0453
From:      "William A. Mahaffey III" <wam@hiwaay.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: compiling static
Message-ID:  <5543F914.9060905@hiwaay.net>
In-Reply-To: <CADK3taLBgDxu4cjfBu%2B4RFeD=34mv66NO1WAzkpb7GLO48BO3g@mail.gmail.com>
References:  <5543E9D5.2030404@paz.bz> <CADK3taLBgDxu4cjfBu%2B4RFeD=34mv66NO1WAzkpb7GLO48BO3g@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 05/01/15 16:28, Alex Merritt wrote:
> On Fri, May 1, 2015 at 5:02 PM, Jim Pazarena <fquest@paz.bz> wrote:
>
>> is there a way to tell cc (clang) to compile with static libraries?
>
> If you want to _compile_ code to a static library, you generate the object
> files and then use "ar" to assemble them together into an archive file (.a).
>
> cc -c file0.c file1.c ...
> ar rcus lib.a file0.o file1.o ...
>
> If you want to _link to_ (if that's what you mean by "compile with") static
> libraries, you may specify the archive path to the linker instead of using
> the dynamic linker flag (-l).
>
> cc prog.c /path/to/lib.a -o prog
>
> There may be other ways I am unfamiliar with. Is this not how gcc does it
> also?
>
> -Alex
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
>

GCC (& most other compilers I am familiar with, such as SGI & Intel 
compiler suites) usually have a flag to the linker to tell it to use 
static linking (using archives, '.a' files, to link 1 big executable 
ready to go by itself) instead of dynamic linking, which is usually the 
default if nothing is specified. I think that is what the OP was asking 
about ....

-- 

	William A. Mahaffey III

  ----------------------------------------------------------------------

	"The M1 Garand is without doubt the finest implement of war
	 ever devised by man."
                            -- Gen. George S. Patton Jr.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5543F914.9060905>