libftdi Archives

Subject: Re: Can not link with libftdi

From: Ori Idan <ori@xxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Fri, 15 Feb 2013 05:30:20 +0200


On Fri, Feb 15, 2013 at 4:48 AM, Xiaofan Chen <xiaofanc@xxxxxxxxx> wrote:
On Fri, Feb 15, 2013 at 4:00 AM, Jim Paris <jim@xxxxxxxx> wrote:
> Ori Idan wrote:
>> I tried: gcc -o i2csend i2csend.c -lftdi
>>
>> Just changing -lftdi to be at the end of the command line and it workd.
>> I still wonder why?
>
> Your GCC probably passes --as-needed to the linker by default.  Ubuntu
> started doing this in Natty and Debian in Wheezy.  This means the
> linker only pulls in symbols from a library if it needs them.  When
> you put libftdi first, none of those symbols are needed yet and so
> nothing gets included.
>
> See e.g. http://wiki.debian.org/ToolChain/DSOLinking#Onlylinkwithneededlibraries

Interesting to know that. I met similar problems and I was
also wondering what happened.

The Debian Wiki page is down now but Ubuntu wiki seems to
be even more detail.

+++++
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition
"The --as-needed option also makes the linker sensitive to
the ordering of libraries on the command-line. You may need to
move some libraries later in the command-line, so they come
after other libraries or files that require symbols from them.
For example, the following link line is wrong, and needs to be
changed so that libraries come after objects that use them:

 gcc -Wall -lwheel -lcar -ltruck -o racetrack racetrack.c"
++++++++++++++++

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.

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)

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.
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.

I am working on i2csend and i2cget utitilies that make use of all available channels on the chip and use the GPIO lines (I am using them to drive external i2c demultiplexer to allow me to have up to 24 i2c channels in my system.

-- 
Ori Idan



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread