Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » How to link the libi2c-dev library correctly
icon5.gif  How to link the libi2c-dev library correctly [message #1711598] Sat, 17 October 2015 22:20 Go to next message
Cleber Marques is currently offline Cleber MarquesFriend
Messages: 2
Registered: April 2015
Junior Member
I really have been working so hard tring to figure out how to link a library correctly. I hope get some useful help here!

I've tried to compile a single program in C to read and write to a device through I2C bus but I'm getting these errors:
make: *** [STRME_v2] Error 1
recipe for target 'STRME_v2' failed 
undefined reference to `i2c_smbus_read_byte_data' 
undefined reference to `i2c_smbus_write_byte_data'


The functions i2c_smbus_read_byte_data and i2c_smbus_write_byte_data are defined in the libi2c-dev. using the command sudo dpkg -L libi2c-dev (Linux) I located the the library's path: /usr/include/linux/

So, all I did to link was:
Browsing to "Properties > C/C++ Build > Settings > Cross GCC Linker > Libraries"
and added "libi2c-dev" in "Libraries (-l)" and added "/usr/include/linux" in "Library search path (-L)"

cannot find libi2c-dev
make: *** [STRME_v2] Error 1
recipe for target 'STRME_v2' failed


It looks more like a linker error. I've no idea how to make it working! I'm stuck on this step for days. I need to make it working to advance on my project to conclude the graduation (with very short deadline!).

PS: I didnt forget the #include <linux/i2c-dev.h> in my code!

Thank in advance!
Re: How to link the libi2c-dev library correctly [message #1711639 is a reply to message #1711598] Sun, 18 October 2015 20:40 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Not really sure what you did and what linker you are using but if it isn't GCC but has similar options, you would supply both -L<path to lib(s)> -l<lib>. The -l option should not include "lib" as it will be added which in your case would be "-li2c-dev". Optionally, if it's an obvious library (ends in .a and .so), you could place a complete path specification to it on the command line without using an option and the linker will figure it out. I use my own make files and am not really sure how to get eclipse to provide a full path. However, I think you can supply a full path and name with the -l option though I've never tried it.

Again this is assuming what you are using works like GCC.
FWIW: Here are the GNU ld command line options.
ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html#SEC3

EDIT:

I just tried -l<full path and name> and it didn't work.
Also, I'm not really sure it isn't treating the naked .a file as a bunch of objects and all them are being dragged in. The names I'm using don't follow normal naming conventions that -l assumes so -l is not an, er, option.


[Updated on: Sun, 18 October 2015 23:31]

Report message to a moderator

Re: How to link the libi2c-dev library correctly [message #1711722 is a reply to message #1711598] Mon, 19 October 2015 12:48 Go to previous message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
It seems that you're making a cross-compilation to another Linux installation (Raspberry?). Please note that the shared libraries of the host Linux hardly ever can be linked to a cross-compiled executable.

Please tell:
- What is the development computer operating system?
- What is the target processor / operating system?
- Is the development library from the development or target
processor repository?
- Is the library an archive file (.a) or a shared library (.so)?



--

Tauno Voipio
Previous Topic:Link LibBoost to Eclipse
Next Topic:Eclipse CDT and Visual Studio 2013 toolchain
Goto Forum:
  


Current Time: Fri Apr 19 10:51:26 GMT 2024

Powered by FUDForum. Page generated in 0.02155 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top