miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

How to use two libraries at the same time on Geany

Mon Jul 10, 2017 7:06 am

Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 9:25 am

How have you tried to do it so far ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

LdB
Posts: 1231
Joined: Wed Dec 07, 2016 2:29 pm

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 11:41 am

I got lost isn't Geany just a text editor?

Or is he saying he doesn't know how to do
#include "library1"
#include "library2"

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 11:48 am

LdB wrote:I got lost isn't Geany just a text editor?
No.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

tommylee2k
Posts: 56
Joined: Mon May 08, 2017 6:23 am

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 2:20 pm

miaomiao wrote:Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!
hi,

I don't know that library, but looks to me like the lib only may be init() once at a time, and you should "release" it after use, so the other one can access it.

if your program looks like

Code: Select all

main() {
    bcm2835_init();
    while (!finished) {
        bcm2835_do_something();
        ...
        sleep(3);   // or whatever
    }
    bcm2835_close();
you could have more success if you change it to

Code: Select all

main() {

    while (!finished) {
        if (bcm2835_init()) {
             bcm2835_do_something();
             bcm2835_close();
        }

        ...
        sleep(3);   // or whatever
    }
the 2nd version only "uses" the lib when it's needed, and releases it afterwards. perhaps this fixes your problem

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 2:50 pm

tommylee2k wrote:
miaomiao wrote:Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!
hi,

I don't know that library, but looks to me like the lib only may be init() once at a time, and you should "release" it after use, so the other one can access it.

if your program looks like

Code: Select all

main() {
    bcm2835_init();
    while (!finished) {
        bcm2835_do_something();
        ...
        sleep(3);   // or whatever
    }
    bcm2835_close();
you could have more success if you change it to

Code: Select all

main() {

    while (!finished) {
        if (bcm2835_init()) {
             bcm2835_do_something();
             bcm2835_close();
        }

        ...
        sleep(3);   // or whatever
    }
the 2nd version only "uses" the lib when it's needed, and releases it afterwards. perhaps this fixes your problem
I can only assume you've not actually used the GPIO libraries, because your answer is wrong in several ways !
The OP is asking about configuring Geany, not about how to actually use the libraries. And since the range device uses USB I can't see how there would be any conflicts at the hardware or software levels.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
buja
Posts: 498
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: How to use two libraries at the same time on Geany

Mon Jul 10, 2017 7:26 pm

miaomiao wrote:Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!
It looks to me you should simply add -lurg and -lbcm2835 to the build command in Geany (Build / Set Build Commands).

Original line:

Code: Select all

gcc -Wall -o "%e" "%f"
New line:

Code: Select all

gcc -Wall -o "%e" "%f" -lbcm2835 -lurg

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 3:52 am

buja wrote:
miaomiao wrote:Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!
It looks to me you should simply add -lurg and -lbcm2835 to the build command in Geany (Build / Set Build Commands).

Original line:

Code: Select all

gcc -Wall -o "%e" "%f"
New line:

Code: Select all

gcc -Wall -o "%e" "%f" -lbcm2835 -lurg

Thank you, I tried again. But still could not get an excutable file.
These are my setting in Geany.
compile: gcc -Wall -c "%f" -l / home/pi/urg_library/include/c -l bcm2835 -lm working directory: /home/pi/urg_library/samples/c
build: gcc -Wall -o "%e"*h working directory: /home/pi/urg_library/samples/c
make: make working directory: /home/pi/urg_library/samples/c

I can bulid and compile succefully, but make failed. Geany showed:

make (in directory: /home/pi/urg_library/samples/c)
gcc -O2 -I../../include/c -c -o open_urg_sensor.o open_urg_sensor.c
make: Warning: File '../../build_rule.mk' has modification time 40310815 s in the future
gcc -O2 -I../../include/c sensor_parameter.c open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o sensor_parameter
gcc -O2 -I../../include/c -c -o get_distance.o get_distance.c
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance
get_distance.o: In function `main':
get_distance.c:(.text.startup+0x10): undefined reference to `bcm2835_init'
get_distance.c:(.text.startup+0x30): undefined reference to `bcm2835_gpio_fsel'
get_distance.c:(.text.startup+0x38): undefined reference to `bcm2835_gpio_set'
<builtin>: recipe for target 'get_distance' failed
collect2: error: ld returned 1 exit status
make: *** [get_distance] Error 1
Compilation failed.

What should I do? Thank you very much.

User avatar
rpdom
Posts: 15184
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 4:21 am

There should be no spaces between the -l and the library name. it should be -lbcm2835, not -l bcm2835

tommylee2k
Posts: 56
Joined: Mon May 08, 2017 6:23 am

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 6:47 am

rpdom wrote:There should be no spaces between the -l and the library name. it should be -lbcm2835, not -l bcm2835
using a space, or not, doesn't make a difference with -l

tommylee2k
Posts: 56
Joined: Mon May 08, 2017 6:23 am

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 6:49 am

miaomiao wrote:
buja wrote:
miaomiao wrote:Hi, I am using URG 04LX scanner on Raspberry Pi 2. I can get the capture value when use the urg library only. However, I am trying to check the capture value e.g. when object distance > 300mm , one LED light up. As the LED needs GPIO so bcm2835 library also needs to be used. How should I set my build command in Geany as bcm2835 and urg library both need to be used? I am using C language. Thank you very much!
It looks to me you should simply add -lurg and -lbcm2835 to the build command in Geany (Build / Set Build Commands).

Original line:

Code: Select all

gcc -Wall -o "%e" "%f"
New line:

Code: Select all

gcc -Wall -o "%e" "%f" -lbcm2835 -lurg

Thank you, I tried again. But still could not get an excutable file.
These are my setting in Geany.
compile: gcc -Wall -c "%f" -l / home/pi/urg_library/include/c -l bcm2835 -lm working directory: /home/pi/urg_library/samples/c
build: gcc -Wall -o "%e"*h working directory: /home/pi/urg_library/samples/c
make: make working directory: /home/pi/urg_library/samples/c

I can bulid and compile succefully, but make failed. Geany showed:

make (in directory: /home/pi/urg_library/samples/c)
gcc -O2 -I../../include/c -c -o open_urg_sensor.o open_urg_sensor.c
make: Warning: File '../../build_rule.mk' has modification time 40310815 s in the future
gcc -O2 -I../../include/c sensor_parameter.c open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o sensor_parameter
gcc -O2 -I../../include/c -c -o get_distance.o get_distance.c
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance
get_distance.o: In function `main':
get_distance.c:(.text.startup+0x10): undefined reference to `bcm2835_init'
get_distance.c:(.text.startup+0x30): undefined reference to `bcm2835_gpio_fsel'
get_distance.c:(.text.startup+0x38): undefined reference to `bcm2835_gpio_set'
<builtin>: recipe for target 'get_distance' failed
collect2: error: ld returned 1 exit status
make: *** [get_distance] Error 1
Compilation failed.

What should I do? Thank you very much.
change
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance

to
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -l bcm2835 -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance

but this is not a geany issue, it's simply your Makefile thats wrong

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 6:52 am

tommylee2k wrote:
rpdom wrote:There should be no spaces between the -l and the library name. it should be -lbcm2835, not -l bcm2835
using a space, or not, doesn't make a difference with -l
It used to be important :shock: , when did that change :?:

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

tommylee2k
Posts: 56
Joined: Mon May 08, 2017 6:23 am

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 11:37 am

PeterO wrote:
tommylee2k wrote:
rpdom wrote:There should be no spaces between the -l and the library name. it should be -lbcm2835, not -l bcm2835
using a space, or not, doesn't make a difference with -l
It used to be important :shock: , when did that change :?:

PeterO
bth: I don't know, on gcc, I was used to the "with space" version for some years, before I even found out that it also works without spaces :-)

perhaps this differs from linker to linker, and platform to platform

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Tue Jul 11, 2017 5:22 pm

gcc documentation:

Code: Select all

-llibrary
-l library
    Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.) 
Looking at the available documentation on https://gcc.gnu.org/onlinedocs/ it appeared sometime between 3.0.4 and 3.1.1 (back in 2002).

Still , it's only a POSIX thing ;)

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to use two libraries at the same time on Geany

Wed Jul 12, 2017 1:13 am

tommylee2k wrote:
change
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance

to
gcc get_distance.o open_urg_sensor.o ../../src/liburg_c.a -l bcm2835 -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh` -o get_distance

but this is not a geany issue, it's simply your Makefile thats wrong
Thanks a lot!!!! It works now! Thank you!

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to use two libraries at the same time on Geany

Wed Jul 19, 2017 9:37 am

Hi, I am using following code in Geany with a laser scanner.

Code: Select all

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


int playSound( char *filename ) {
char command[256];
int status;

/* create command to execute */
sprintf( command, "omxplayer -o local giveway.mp3" );

/* play sound */
status = system( command );

return status;
}

int main( int argc, char *argv[] ) {


//----- TX BYTES -----
	unsigned char tx_buffer[20];
	unsigned char *p_tx_buffer;
	
	p_tx_buffer = &tx_buffer[0];
	*p_tx_buffer++ = 'S';  //receive "S" means stop, then play the music
	if( distance<600)
{	
        /* play the music  */
       playSound( argv[1] );

	if (uart0_filestream != -1)
	{
		int count = write(uart0_filestream, &tx_buffer[0], (p_tx_buffer - &tx_buffer[0]));		//Filestream, bytes to write, number of bytes to write
		if (count < 0)
		{
			printf("UART TX error\n");
		}
	}



return 0;
}
}
else .....
However, raspberry pi could not work with the playSound function and show the below message.

pi@raspberrypi:~/urg_library/samples/c $ sudo ./get_distance

2794 [mm],2637 [mm],0 [mm], (102384 [msec])
2789 [mm],2640 [mm],0 [mm], (103485 [msec])
2794 [mm],2639 [mm],0 [mm], (103585 [msec])
2799 [mm],563 [mm],542 [mm], (103686 [msec])
Audio codec mp3 channels 1 samplerate 22050 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
have a nice day ;)
619 [mm],513 [mm],519 [mm], (103786 [msec])
Audio codec mp3 channels 1 samplerate 22050 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
have a nice day ;)
2790 [mm],2640 [mm],509 [mm], (103886 [msec])
Audio codec mp3 channels 1 samplerate 22050 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
have a nice day ;)
2801 [mm],2642 [mm],0 [mm], (103986 [msec])
urg_get_distance: no error.

What should I do to solve this?
Last edited by miaomiao on Thu Jul 20, 2017 1:16 am, edited 1 time in total.

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Wed Jul 19, 2017 6:02 pm

miaomiao wrote:What should I do to solve this?
Learn how to make posts using quote and code tags properly would be a good step ! As it stands your post is pretty incomprehensible !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 1:23 am

PeterO wrote:
miaomiao wrote:What should I do to solve this?
Learn how to make posts using quote and code tags properly would be a good step ! As it stands your post is pretty incomprehensible !
PeterO
Thank you,I will study and please learn how to talk people properly. Don't be so aggressive.

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 5:02 am

miaomiao wrote:
PeterO wrote:
miaomiao wrote:What should I do to solve this?
Learn how to make posts using quote and code tags properly would be a good step ! As it stands your post is pretty incomprehensible !
PeterO
Thank you,I will study and please learn how to talk people properly. Don't be so aggressive.

:lol: :lol: :lol: :lol:
http://raspi.tv/2017/how-to-ask-for-and ... e-internet
And thread hijacking is frowned upon as well !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 7:10 am

miaomiao wrote:
PeterO wrote:
miaomiao wrote:What should I do to solve this?
Learn how to make posts using quote and code tags properly would be a good step ! As it stands your post is pretty incomprehensible !
PeterO
Thank you,I will study and please learn how to talk people properly. Don't be so aggressive.
don't care about PeterO's statements, already other people have critizided his snooty postings. Probably he is not capable of understanding it, simply ignore it.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12219
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 9:22 am

Please do not make personal attacks!

1dot0
Posts: 430
Joined: Mon Nov 28, 2016 12:31 pm

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 9:38 am

Stiller wrote:
miaomiao wrote:
PeterO wrote: Learn how to make posts using quote and code tags properly would be a good step ! As it stands your post is pretty incomprehensible !
PeterO
Thank you,I will study and please learn how to talk people properly. Don't be so aggressive.
don't care about PeterO's statements, already other people have critizided his snooty postings. Probably he is not capable of understanding it, simply ignore it.
but apart from the moderator's edit:
cum granum salis, I agree, nonetheless I would assume that it's more about "willing to" than "capable of".
miaomiao is not the first one who feels these posts to be agressive.

LdB
Posts: 1231
Joined: Wed Dec 07, 2016 2:29 pm

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 10:36 am

However he is also multi thread posting he put the same detail in another post and I already gave him the answer his code look like it is working given the output. I would guess if he doesn't have any sound he has got it coming out the wrong sound device.

He needs to address the problem of where does he think the sound is going against where it actually is. There are more than one sound output device on a Pi.

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 10:40 am

1dot0 wrote: cum granum salis, I agree, nonetheless I would assume that it's more about "willing to" than "capable of".
I make absolutely no apology for being direct and to the point. If you don't like what I write, then simply add me to your foe list, I don't care if you can't take advice in the spirit it is given.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

1dot0
Posts: 430
Joined: Mon Nov 28, 2016 12:31 pm

Re: How to use two libraries at the same time on Geany

Thu Jul 20, 2017 10:49 am

PeterO wrote:
1dot0 wrote: cum granum salis, I agree, nonetheless I would assume that it's more about "willing to" than "capable of".
I make absolutely no apology for being direct and to the point. If you don't like what I write, then simply add me to your foe list, I don't care if you can't take advice in the spirit it is given.
PeterO
Peter, what you are obviously missing is the difference between "direct and to the point" vs. "aggressive, snooty, and offending". I think I already mentioned that once or twice before, this difference is about kindness, friendlyness, goodwill, social compentence, "Kinderstube", and ability to self-criticism.

Return to “C/C++”