LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-28-2013, 01:06 PM   #1
PeterUK
Member
 
Registered: May 2009
Posts: 281

Rep: Reputation: 16
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
 
Old 08-28-2013, 08:52 PM   #2
ljb643
Member
 
Registered: Nov 2003
Posts: 528

Rep: Reputation: Disabled
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.
 
Old 08-29-2013, 05:55 AM   #3
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ljb643 View Post
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"
 
Old 08-29-2013, 08:27 AM   #4
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
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
 
Old 08-29-2013, 09:07 AM   #5
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
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
 
Old 08-29-2013, 08:55 PM   #6
ljb643
Member
 
Registered: Nov 2003
Posts: 528

Rep: Reputation: Disabled
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...
 
Old 08-29-2013, 09:16 PM   #7
ljb643
Member
 
Registered: Nov 2003
Posts: 528

Rep: Reputation: Disabled
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.
 
Old 08-30-2013, 07:45 AM   #8
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ljb643 View Post
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! :-)
 
Old 08-30-2013, 07:50 AM   #9
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
UPDATE:1.1

Now I would like to get going the libusbx how do I add the heater for that? does anyone know?
 
Old 08-30-2013, 07:51 PM   #10
ljb643
Member
 
Registered: Nov 2003
Posts: 528

Rep: Reputation: Disabled
For libusbx:
https://github.com/libusbx/libusbx/wiki
http://sourceforge.net/projects/libusbx/

I don't know if you can have both libusb (from Slackware) and libusbx on your system at the same time. Given that libusbx is intended as a "drop-in replacement" for libusb, there might be conflicts.
 
Old 09-01-2013, 05:10 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
Shouldn't this:
Code:
#include "/usr/include/libusb-1.0/libusb.h"
be this?:
Code:
#include <libusb-1.0/libusb.h>
 
Old 09-01-2013, 06:48 AM   #12
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by gnashley View Post
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?
 
Old 09-01-2013, 01:30 PM   #13
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
Double quotes means relative to this dir -I#m not sure if the leading '/' overrides that or not... worth a try though or no?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware Perl Library roscioa Slackware 1 11-19-2008 12:21 AM
GD Library not support Slackware 12.1 Slackwan Slackware 9 10-14-2008 06:03 AM
usb library problem b123coder Linux - Hardware 1 04-25-2006 12:59 AM
LAPACK library for Slackware 9.1 rsamurti Slackware 1 06-11-2004 03:05 PM
HP Deskjet (USB) & CUPS & Slackware 9.1: Unable to open USB device "usb:/dev/usb/lp0&qu arnostienen Slackware 2 01-29-2004 04:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration