Sysprogs forums › Forums › VisualGDB › Raspberry PI – How to add C library to project not already i
- This topic has 3 replies, 2 voices, and was last updated 10 years, 11 months ago by ket.
-
AuthorPosts
-
January 27, 2014 at 18:56 #735ChuckZParticipant
Goal: Add a new library (e.g. libusb) to my project so that I can use it.
Configuration:
* Host – Visual Studio 2012 on Windows 8.1
* Target – Raspberry PI B
* Build using the target Raspberry PI (and prefer to keep it that way rather than using a cross complier)I can build and debug a standard Hello World application just fine. When I try to use something from the new library, I cannot build. This is the problem I need to solve.
On the Raspberry PI, I was able to get the libusb project using the Linux command apt-get install libusb-dev
This resulted in the header usb.h being installed to the /usr/include directory of the target.
I am not really certain which library I should link to. Either something in /lib/arm-linux-gnuabihf or /usr/lib/arm-linux-gnuabihfI can transfer files to and from the host and target using a USB flash drive.
What is the procedure for getting the headers and libs to my host PC so that VisualGDB will deploy and then build correctly?
Thanks for any assistance.January 28, 2014 at 02:26 #2928ketParticipantHi,
If you are not using a cross-compiler then the library and its headers are not needed on the Windows host. This is because building takes place on the Raspberry Pi target, the sources of your project are transferred over to the target over SSH just before building, all the libraries are constantly on the target.
You do need to tell the project which libraries and include directories you are using. You can do that on the Makefile settings page in VisualGDB Project Properties. Add the include directory there and the library name without the lib prefix and type suffixes (for libusb that is probably just usb). Normally the linker should search common library directories, but if the library is not found then add the library directory as well in the settings.
January 28, 2014 at 18:52 #2927ChuckZParticipantThanks for the reply, ket.
I did figure out some of the things I needed as well which I wanted to share.
There is value to me in getting headers back from the target to the Windows host even if the PI does your build: It gives you intellisense.
They get stored into locations like this…C:UsersMyNameAppDataLocalVisualGDBRemoteSourceCache10.124.212.55 000includec++4.6
When I created a new Hello world GDB I chose to see the advanced options. That told me a lot about what is going on under the hood. I chose to refresh the cache (with each build?) and figured that would ensure I get any new headers installed on the target.
For linking, I found that many of the libraries are included by setting special linker flags. For example, to get the usb and pthread libraries, you change the .mak files to look like this.
ADDITIONAL_LINKER_INPUTS := -lusb -lpthreadI don’t do a lot of Linux C development and this is probably common knowledge to Linux developers.
January 28, 2014 at 21:36 #2926ketParticipantHi,
If you add include directories on the Makefile settings page, then the same directory is also added to IntelliSense directories and cached if it did not exist before. So, the IntelliSense support is automatic.
The IntelliSense cache is not refreshed at each build because it would take too much time, but it is refreshed when new include directories are added. You can also refresh it manually in VisualGDB Project Properties on the IntelliSense directories page or globally for that machine in Tools->VisualGDB Source Cache Manager.If you add library names on the Makefile settings page e.g. usb, they get passed to the linker exactly like -lusb. As passing library directories and names to the linker is done in a standard way, VisualGDB makefiles have separate fields for them and adding the appropriate prefix is automatic. You should only need to use the additional linker inputs field if adding something non-standard that should be passed to the linker as-is.
-
AuthorPosts
- You must be logged in to reply to this topic.