Libraries installed on the RPi need to be available for eclipse on windows for it to compile then they are used. The following is basically a copy of the solution we came up with for mysql here.

Getting Compiled Library Files Into Eclipse For Windows

If you are not coding on the RPi itself, for instance developing using eclipse for windows, you need to copy the library files you need to use if your cross compiler toolchain doesn't have them.

Getting Individual Files – MySQL Example

The following example using the mysql library is not based on any expert knowledge of ours, it is instead the results of our trial and error hitting it with a hammer until it worked.  Its a good solution to the problem if you are using a single library where you can work out where the library files are and copy them over.  its not so good when you need a lot of libraries, e.g. for GTK.

1 – Get the header files

Copy the header files directory on the RPi, e.g.:


/usr/include/mysql

to your projects directory.  Use this to include it in your C code file:


#include "mysql/mysql.h"
2 – Create Object Files

Create a file called main.c containing some code which uses the library you want to use, e.g. this:


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <mysql.h>

int main(int argc, char **argv)
{
	MYSQL *mysql1;
	mysql1 = mysql_init(NULL);
}

Save it in a directory on the RPI, then on the command line go to that directory and use this to compile it:


g++ main.c `mysql_config --cflags` `mysql_config --libs`

Now find where the library files are stored.  Its often this:

/usr/lib/arm-linux-gnueabihf

copy the .a and .o/.so output files, e.g.:

libmysqlclient.a
libmysqlclient.so

Paste them into your windows machine folder:

C:\cygwin\opt\cross\x-tools\arm-unknown-linux-gnueabi\arm-unknown-linux-gnueabi\sysroot\usr\lib\

Now in eclipse, right click your project > Properties > C/C++ Build > Settings > Cygwin C++ Linker > Libraries.  Add a new library entry, e.g.:

mysqlclient

Now build the project.  The make may fail with warnings saying the library references other files which need to be added in also.  For us files listed in the eclipse build warnings we're all in this folder:

/lib/arm-linux-gnueabihf/

But if you need to search for them, install and use mlocate to find them on the RPi.

Find each one and copy it into the same cygwin windows library folder.

Its simple and dirty but it works!

 

 

 

Other Approaches Tried But Failed

Copying All Library Files Off The RPi

If you are using A Linux PC you could simply insert the SD card and copy these directories off it.  Otherwise for Windows use a program like WinSCP.  Warning – there are lots of files so this is very very slow!

​Copy the following directories off the RPi

​/usr
/lib

You still need to tell eclipse where to find the files which is the problem – see below

Use A Network Share On The RPi

Follow the instructions here to setup "path=/" to be shared on the RPi using samba and set it as a network drive in Windows explorer. This gives your windows machine direct access to the /usr and /lib directories on the RPi which you can map to a drive letter.  As above you still need to tell eclipse where to find the files which is the problem – see below

Manually copy the files over

Find out which folders are needed and manually copy them over.

So now what

You've got the folders you need accessible using one of the methods above.  Now the problem which is illustrated by developing using GTK which uses lots of libraries

Discover The Paths You Need To Access

Run this command to get a list of all libraries used by GTK


pkg-config --cflags gtk+-3.0

pgk-config returns metadata about installed libraries. So when using a specific library you can use it to provide a list of the necessary dependent libraries and include files that are needed.  In this example it gave:


-pthread -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12

If we we're compiling on the RPi we would use the pgk-config command to the compiler to get all these paths automatically but we're off the RPi so we need to set them to be included manually instead.

Now we can manually add all these paths to eclipse in project properties > C/C++ Build > Settings > Cygwin C++ Compiler > Includes using paths like this:


"../rpi-libs-copy/gtk-3.0"
"../rpi-libs-copy/pango-1.0"

The reason we have to use a relative path is that cygwin won't allow paths with ":" in so c:/ is out etc.  It also doesn't handle network paths for some reason, e.g. "\\RASPBERRYPI\pihome/usr/include/libpng12" – it just says any file in there is not found.  So actually based on this only the method of copying the files off the RPi and then storing them in a directory called rpi-libs-copy at the same level of your projects src directory will work, There must be a solution to this but we gave up looking as there is another problem waiting to be found once you work around this cygwin issue, the libraries.

You can use this command to find out what libraries GTK needs, again a command you woudl give to the compiler on the RPi itself:


pkg-config --libs gtk+-3.0

You can then manually add each of these libraries to eclips.  Using GTK requires several libraries directly but also lots of other libraries are used by these libraries.  As you are not on the Rpi you need to tell eclipse where they are.  You can use a ":" on the libraries include path which means you can share the RPi drive as a network drive, map it to say drive letter R on your windows machine and use this as a library search path ""r:\usr\lib\arm-linux-gnueabihf"". But when you build you'll get error messages for lots of missing libraries which are obviously elsewhere.  At this point we gave up and moved to compiling on the RPi itself.  The accessing of files issues can be worked around but eclipse not having knowledge of installed libraries and where they are just makes it a nightmare when using somethign like GTK.  Even if taking the time to manually work through everything it can't find and adding it you're then crossing your fingers that things don't change when you next update the RPi, which might move things, add things, require new copies of files to be copied over, etc.

 

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *