On Fri, Feb 15, 2013 at 11:30 AM, Ori Idan <ori@xxxxxxxxxxxxxxxxx> wrote:
> On Fri, Feb 15, 2013 at 4:48 AM, Xiaofan Chen <xiaofanc@xxxxxxxxx> wrote:
>> How do I know if my system GCC passes --as-needed to
>> the linker by default?
>
> You can view the default configuration of gcc using gcc -dumpspecs.
> Note however that this gives you a lot of output so you might want to filter
> it through grep.
Hmm, not easy to interprete the result. But I can see that gcc under
Mac OS X (4.2 with Xcode and 4.7 with HomeBrew) do not support
--as-needed since it returns nothing about "as-needed).
Under Ubuntu 12.10, I am not so sure how to interpret the result.
mcuee@Ubuntu1210VM:~$ gcc -dumpspecs | grep as-needed
%{!r:--build-id} --no-add-needed --as-needed %{!static:--eh-frame-hdr}
%{m64:-m elf_x86_64} %{m64|mx32:;:-m elf_i386}
%{mx32:-m elf32_x86_64} --hash-style=gnu
%{shared:-shared} %{!shared: %{!static:
%{rdynamic:-export-dynamic} %{m64|mx32:;:-dynamic-linker
%{muclibc:/lib/ld-uClibc.so.0;:%{mbionic:/system/bin/linker;:/lib/ld-linux.so.2}}}
%{m64:-dynamic-linker
%{muclibc:/lib/ld64-uClibc.so.0;:%{mbionic:/system/bin/linker64;:/lib64/ld-linux-x86-64.so.2}}}
%{mx32:-dynamic-linker
%{muclibc:/lib/ldx32-uClibc.so.0;:%{mbionic:/system/bin/linkerx32;:/libx32/ld-linux-x32.so.2}}}}
%{static:-static}}
%{static|static-libgcc:-lgcc
-lgcc_eh}%{!static:%{!static-libgcc:%{!shared-libgcc:-lgcc --as-needed
-lgcc_s --no-as-needed}%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}}}
> I asked similar question at stackoverflow and I got there an answer that is
> worth sharing here.
> Someone there offered me to use the following command line:
> gcc $(pkg-config --cflags libftdi) -o i2csend i2csend.c $(pkg-config
> --libs libftdi)
Yes this is the way to go under Linux, Mac OS X and Cygwin
where you have pkg-config. It may not work well under MinGW
Windows since normally there is no pkg-config under MinGW
(but you can use pkg-config lite).
> Note that this command line will add flags that may be required by the
> library and at the end put the library and any other libraries that may be
> required by it.
Not really, this is using dynamic link to libftdi.
The libftdi1.pc does not seem to support static link where you
need to add more libraries.
> In the case of libftdi it seems that it does not require
> special flags or other libraries.
>
> But I think this is a good practice to use this command line.
> This new command line will be pushed to my github project
> once I'm done with the additions I want.
--
Xiaofan
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|