# Using the libusbmuxd libraries for iPhone communication



## PVB (Aug 11, 2017)

Hi, 
I need to connect my iPhone to the freebsd. I have already installed the usbmuxd and it definitely works. As soon as I connect the iPhone to my freebsd host, (while the usbmuxd is running) the messages pop up indicating that the Apple iPhone is connected and its ID and serial number etc are printed out.

However, I want to develop a small application to start with which will just register for notification and print out the details when a iPhone is connected. 

1. How do I add the libraries (libusbmuxd, libimobiledevice etc) in my C code? What is the path to the libusbmux.h etc?
2. How do I find out where the libraries are installed? or if they are in the default path for the g++ compiler?


----------



## tobik@ (Aug 11, 2017)

`pkg info -l libimobiledevice libusbmuxd` lists all files installed by the packages.

Since both comms/libimobiledevice and comms/libusbmuxd also install a .pc file for devel/pkgconf you can get the appropriate compiler and linker flags with `pkg-config --cflags libimobiledevice-1.0 libusbmuxd` and `pkg-config --libs libimobiledevice-1.0 libusbmuxd`.


----------



## PVB (Aug 11, 2017)

Ok now I know where the libraries are. But how do I add it to the default paths? Currently when I try to build a very simple program, I get following error.


```
In function `main':
main.cpp:(.text+0x58): undefined reference to `usbmuxd_get_device_list'
collect2: error: ld returned 1 exit status
```

So it looks like all I need to do is add the path to the default path for g++ compiler and it should work. How do I do that.


----------



## ljboiler (Aug 12, 2017)

You don't need to put new things (libraries, header files) in the g++ default path, you just tell g++ to go look in other places as well as the default.

Those `pkg-config` commands tobik@ showed above will give you the extra stuff you need to add to the g++ command to do just that.


----------



## PVB (Aug 18, 2017)

I got it...I didn't add it to the default path but while compiling I gave the link to the library location and gave the name of the library to use.

You just execute the following command

g++ -L/usr/local/lib -Wall -o test main.cpp -lusbmuxd

even though the library name in the /usr/local/lib is libusbmuxd, the name in the command should skip the "lib" as the compiler automatically assumes the "lib" prefix


----------

