Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-28-2013, 01:06 PM
|
#1
|
Member
Registered: May 2009
Posts: 281
Rep:
|
Slackware- usb library
Hi! I have some question about USB library,
I have used the usb library before like -lusb and have managed to use the libusb with no problem before but now I am compiling sigrok-cli bits by bits trying to understand its structure but I am running into a problem.
At the moment I have fix the problem usb include by changing "#include <libusb.h>" to "#include <usb.h>"
I have this packages installed.
libusb-1.0.9-i486-1
libusb-compat-0.1.4-i486-1
usbutils-006-i486-1
I know libusb you called it like -lusb , right? What about libusb-compat, how do I call those library into the link at the compile terminal with gcc.
the error I am getting are:
Code:
gcc -lusb -otest sigrok_test.c `pkg-config --cflags --libs glib-2.0`
In file included from hwdriver.c:28:0,
from sigrok_test.c:19:
libsigrok-internal.h:49:2: error: unknown type name 'libusb_context'
libsigrok-internal.h:99:36: error: unknown type name 'libusb_context'
libsigrok-internal.h:171:36: error: unknown type name 'libusb_device_handle'
libsigrok-internal.h:173:35: error: unknown type name 'libusb_device'
libsigrok-internal.h:180:29: error: unknown type name 'libusb_context'
libsigrok-internal.h:181:25: error: unknown type name 'libusb_context'
In file included from sigrok_test.c:19:0:
hwdriver.c:66:3: error: 'SR_CONF_EXTERNAL_CLOCK' undeclared here (not in a function)
hwdriver.c:98:3: error: 'SR_CONF_VOLTAGE_THRESHOLD' undeclared here (not in a function)
hwdriver.c:98:30: error: 'SR_T_DOUBLE_RANGE' undeclared here (not in a function)
make: *** [glib2] Error 1
for instance I looked at "libusb_context" and its on here so its part of libusb, why is it giving error?
to get to this error you need to compile:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <usb.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <libsigrok/libsigrok.h>
#include "sigrok-cli.h"
#include "hwdriver.c"
#define DEFAULT_OUTPUT_FORMAT "bits:width=64"
static struct sr_context *sr_ctx = NULL;
static uint64_t limit_samples = 0;
static uint64_t limit_frames = 0;
static struct sr_output_format *output_format = NULL;
static int default_output_format = FALSE;
static char *output_format_param = NULL;
static GByteArray *savebuf;
static gboolean opt_version = FALSE;
static gint opt_loglevel = SR_LOG_WARN; /* Show errors+warnings per default. */
static gboolean opt_scan_devs = FALSE;
static gboolean opt_wait_trigger = FALSE;
static gchar *opt_input_file = NULL;
static gchar *opt_output_file = NULL;
static gchar *opt_drv = NULL;
static gchar *opt_config = NULL;
static gchar *opt_probes = NULL;
static gchar *opt_triggers = NULL;
static gchar *opt_pds = NULL;
static gchar *opt_input_format = NULL;
static gchar *opt_output_format = NULL;
static gchar *opt_show = NULL;
static gchar *opt_time = NULL;
static gchar *opt_samples = NULL;
static gchar *opt_frames = NULL;
static gchar *opt_continuous = NULL;
static gchar *opt_set = NULL;
static GOptionEntry optargs[] = {
{"version", 'V', 0, G_OPTION_ARG_NONE, &opt_version,
"Show version and support list", NULL},
{"loglevel", 'l', 0, G_OPTION_ARG_INT, &opt_loglevel,
"Set loglevel (5 is most verbose)", NULL},
{"driver", 'd', 0, G_OPTION_ARG_STRING, &opt_drv,
"The driver to use", NULL},
{"config", 'c', 0, G_OPTION_ARG_STRING, &opt_config,
"Specify device configuration options", NULL},
{"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &opt_input_file,
"Load input from file", NULL},
{"input-format", 'I', 0, G_OPTION_ARG_STRING, &opt_input_format,
"Input format", NULL},
{"output-file", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_file,
"Save output to file", NULL},
{"output-format", 'O', 0, G_OPTION_ARG_STRING, &opt_output_format,
"Output format", NULL},
{"probes", 'p', 0, G_OPTION_ARG_STRING, &opt_probes,
"Probes to use", NULL},
{"triggers", 't', 0, G_OPTION_ARG_STRING, &opt_triggers,
"Trigger configuration", NULL},
{"wait-trigger", 'w', 0, G_OPTION_ARG_NONE, &opt_wait_trigger,
"Wait for trigger", NULL},
{"scan", 0, 0, G_OPTION_ARG_NONE, &opt_scan_devs,
"Scan for devices", NULL},
{"show", 0, 0, G_OPTION_ARG_NONE, &opt_show,
"Show device detail", NULL},
{"time", 0, 0, G_OPTION_ARG_STRING, &opt_time,
"How long to sample (ms)", NULL},
{"samples", 0, 0, G_OPTION_ARG_STRING, &opt_samples,
"Number of samples to acquire", NULL},
{"frames", 0, 0, G_OPTION_ARG_STRING, &opt_frames,
"Number of frames to acquire", NULL},
{"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous,
"Sample continuously", NULL},
{"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
/* Convert driver options hash to GSList of struct sr_config. */
static GSList *hash_to_hwopt(GHashTable *hash)
{
const struct sr_config_info *srci;
struct sr_config *src;
GList *gl, *keys;
GSList *opts;
char *key, *value;
keys = g_hash_table_get_keys(hash);
opts = NULL;
for (gl = keys; gl; gl = gl->next) {
key = gl->data;
if (!(srci = sr_config_info_name_get(key))) {
g_critical("Unknown option %s", key);
return NULL;
}
src = g_try_malloc(sizeof(struct sr_config));
src->key = srci->key;
value = g_hash_table_lookup(hash, key);
src->data = g_variant_new_string(value);
opts = g_slist_append(opts, src);
}
g_list_free(keys);
return opts;
}
int main()
{
printf("test\n");
return (0);
}
I had to pull some files from the other project (sigrok) I think libsigrok must be providing the library as I dont have sigrok installed :
Code:
you need:
sigrok-cli.h
hwdriver.c
libsigrok.h
config.h
libsigrok-internal.h
Also I would like to ask about that last file libsigrok-internal.h it does things like:
struct sr_context {
#ifdef HAVE_LIBUSB_1_0
libusb_context *libusb_ctx;
#endif
};
this look all standards declaration but I am not sure where do I have to add the define "HAVE_LIBUSB_1_0"? Is that at compiling time?
you can get all the whole thing here
|
|
|
08-28-2013, 08:52 PM
|
#2
|
Member
Registered: Nov 2003
Posts: 528
Rep: 
|
Slackware (14, anyway) supports 2 versions of the USB library: 0.1 and 1.0. Support for the older libusb 0.1 is available with the libusb-compat package. The header is <usb.h>, and the library to link with is -lusb.
To use the newer version, you need to #include <libusb-1.0/libusb.h> (or, you can use a -I option on the compile command line with /usr/include/libusb-1.0) and just #include <libusb.h>). The library you link with must be specified as -lusb-1.0 I think.
The error messages you are getting make me think you are trying to compile something that needs the newer libusb-1.0, so I think you are using the wrong header file to start.
|
|
|
08-29-2013, 05:55 AM
|
#3
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
Quote:
Originally Posted by ljb643
Slackware (14, anyway) supports 2 versions of the USB library: 0.1 and 1.0. Support for the older libusb 0.1 is available with the libusb-compat package. The header is <usb.h>, and the library to link with is -lusb.
To use the newer version, you need to #include <libusb-1.0/libusb.h> (or, you can use a -I option on the compile command line with /usr/include/libusb-1.0) and just #include <libusb.h>). The library you link with must be specified as -lusb-1.0 I think.
The error messages you are getting make me think you are trying to compile something that needs the newer libusb-1.0, so I think you are using the wrong header file to start.
|
Thanks for this, after include the header like that the error goes away, I remove the modification as leave as it was to test at the compile line but for a reason the error dont come back? :-/
The other error is different into my local library I looked at "SR_CONF_EXTERNAL_CLOCK" and it appear into the one I downloaded recently but the one into usr/local...libsigrok.h it has not got it declared, so that error, I tried to load it manually changing "#include <libsigrok/libsigrok.h>" to local files, it call other files like proto.h,version.c,..... which I added but then give some other error to a .o files, such as"
/tmp/ccoUoxGy.o: In function `sr_driver_init':
sigrok_test.c  .text+0x1e): undefined reference to `sr_err'"
I looked into my "sigrok_test.c" that is not even that function how can track from where is creating "/tmp/ccoUoxGy.o"
|
|
|
08-29-2013, 08:27 AM
|
#4
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
Update 1:
I was feeling un-easy about this new libusb so decided to do further test by trying to compile something from the example page here the file is called "listdevs.c" I think it just list all devices?
so I went ot check that I have "libusb.h" which its under "/usr/include/libusb-1.0/" then edit the file by rename:
#include "libusb.h" to #include "/usr/include/libusb-1.0/libusb.h"
The compile:
gcc -otest listdevs.c -lusb-1.0
I get this error:
Quote:
/tmp/cc0aL1aH.o: In function `print_devs':
listdevs.c .text+0xc3): undefined reference to `libusb_get_port_numbers'
collect2: error: ld returned 1 exit status
|
But after some search I found here that its defined 'libusb_get_port_numbers' is this libusb 1.0 right?
I search on that header file libusb.h under usr/include and there is nothing in there.
Have I missed something? What is the right way to compile this file?
I've tried several variation and nothing works:
modified the file as :
#include "libusb.h"
#include <libusb.h>
#include "/usr/include/libusb-1.0/libusb.h"
#include <libusb-1.0/libusb.h>
(oblivious doing the variation accordingly to what I was going to call at the terminal)
the compile:
gcc -otest listdevs.c -lusb-1.0
gcc -otest listdevs.c -lusb-1.0 -lusb
gcc -otest listdevs.c -l/usr/include/libusb-1.0/
gcc -otest listdevs.c -l/usr/include/libusb-1.0
gcc -otest listdevs.c -L/usr/include/libusb-1.0
Also with include as here
gcc -otest listdevs.c -I/usr/include/libusb-1.0
|
|
|
08-29-2013, 09:07 AM
|
#5
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
Update 2:
I also try this another example which I though would be easier but it does compile but when I test it give :
This is a Test
Segmentation fault
To compile:
gcc -Wall -otest usb_test2.c -lusb-1.0
The code is this one:
Quote:
#include <stdio.h>
#include <stdbool.h>
#include "/usr/include/libusb-1.0/libusb.h"
static bool
is_interesting(libusb_device *device)
{
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(device, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return false;
}
if ((desc.idVendor == 0x04b4) && (desc.idProduct == 0x8613))
return true;
return false;
}
int main()
{
printf("This is a Test\n");
// discover devices
libusb_device **list;
libusb_device *found = NULL;
ssize_t cnt = libusb_get_device_list(NULL, &list);
ssize_t i = 0;
int err = 0;
//if (cnt < 0)
// error();
for (i = 0; i < cnt; i++) {
libusb_device *device = list[i];
if (is_interesting(device)) {
found = device;
break;
}
}
if (found) {
libusb_device_handle *handle;
err = libusb_open(found, &handle);
// if (err)
// error();
// etc
}
libusb_free_device_list(list, 1);
return (0);
}
|
It comes from here and here
|
|
|
08-29-2013, 08:55 PM
|
#6
|
Member
Registered: Nov 2003
Posts: 528
Rep: 
|
Your first example "listdevs.c" is written for a different library, "libusbx". As you found, it won't work with libusb - neither old nor new versions. They are different projects, although they seem to have a lot in common - maybe libusbx is a fork.
I'll take a look at your second example...
|
|
|
08-29-2013, 09:16 PM
|
#7
|
Member
Registered: Nov 2003
Posts: 528
Rep: 
|
Re: example code under Update 2, you must initialize libusb by calling libusb_init(NULL) before making any other libusb call, else your program will - you know, segfault.
|
|
|
08-30-2013, 07:45 AM
|
#8
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
Quote:
Originally Posted by ljb643
Re: example code under Update 2, you must initialize libusb by calling libusb_init(NULL) before making any other libusb call, else your program will - you know, segfault.
|
Thanks! I should have analyze the code futher down! :-O, I added also the debug mode and some message to see if its connected or not, it works fine! :-)
|
|
|
08-30-2013, 07:50 AM
|
#9
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
UPDATE:1.1
Now I would like to get going the libusbx how do I add the heater for that? does anyone know?
|
|
|
09-01-2013, 05:10 AM
|
#11
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
Shouldn't this:
Code:
#include "/usr/include/libusb-1.0/libusb.h"
be this?:
Code:
#include <libusb-1.0/libusb.h>
|
|
|
09-01-2013, 06:48 AM
|
#12
|
Member
Registered: May 2009
Posts: 281
Original Poster
Rep:
|
Quote:
Originally Posted by gnashley
Shouldn't this:
Code:
#include "/usr/include/libusb-1.0/libusb.h"
be this?:
Code:
#include <libusb-1.0/libusb.h>
|
I think its the same! Right?
|
|
|
09-01-2013, 01:30 PM
|
#13
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
Double quotes means relative to this dir -I#m not sure if the leading '/' overrides that or not... worth a try though or no?
|
|
|
All times are GMT -5. The time now is 12:59 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|