maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   liblocation, undefiend reference (https://talk.maemo.org/showthread.php?t=34770)

hopbeat 2009-11-19 17:50

liblocation, undefiend reference
 
Hello,

trying to compile example using:

Code:

gcc -Wall `pkg-config --cflags glib-2.0, liblocation --libs glib-2.0, liblocation` -o gps gps.cpp
I'm getting errors:

Code:

/var/tmp/cc447Dm5.o: In function `main':
gps.cpp:(.text+0x2c): undefined reference to `location_gpsd_control_get_default()'
gps.cpp:(.text+0x38): undefined reference to `location_gps_device_get_type()'
/var/tmp/cc447Dm5.o: In function `start_location(void*)':
gps.cpp:(.text+0x16c): undefined reference to `location_gpsd_control_start(_LocationGPSDControl*)'
/var/tmp/cc447Dm5.o: In function `on_changed(_LocationGPSDevice*, void*)':
gps.cpp:(.text+0x280): undefined reference to `location_gpsd_control_stop(_LocationGPSDControl*)'


maybe I'm tired, but I have no idea how to fix this :(

I'm using final SDK for Maemo 5, same effect on both armel and x86.

hopbeat 2009-11-19 18:39

Re: liblocation, undefiend reference
 
Answering my own question:

adding

Code:

extern "C"
{
#include <location/location-gps-device.h>
#include <location/location-gpsd-control.h>
}

may prove useful. It was a long day...

ESmith 2010-04-27 18:33

Re: liblocation, undefiend reference
 
Hi!

I encounter a similar problem and have long been looking for an answer to it, but no success so far.

I get the same error message, even when trying it with the sample code.

I am using the Virtual Image SDK and I am writing in C, though and the headers are of course included.

Any hint on how to solve is very welcome.

ES

Joorin 2010-04-27 18:53

Re: liblocation, undefiend reference
 
Quote:

Originally Posted by ESmith (Post 630296)
Hi!

I encounter a similar problem and have long been looking for an answer to it, but no success so far.

I get the same error message, even when trying it with the sample code.

I am using the Virtual Image SDK and I am writing in C, though and the headers are of course included.

Any hint on how to solve is very welcome.

ES

As always: submit exact compiler command together with exact error output. Without that, it's almost impossible to guess what's going on.

ESmith 2010-04-28 08:46

Re: liblocation, undefiend reference
 
Thanks for the heads-up, Joorin, surely nobody could help me with that little information, I understand.
Something had to be wrong with my first post...

So, here goes, I am as well trying to compile the location API example code, as per the very first post in this thread. I am using the Virtual Image SDK in VMware on a Mac and I compile inside ESbox.

Code:

gcc  -O0 -g  -o helloworldwithdebiansupport  main.o -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgnomevfs-2 -lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0  -pthread -lhildon-1 -lhildonfm -lgtk-x11-2.0 -lgnomevfs-2 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0  -losso -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0
And the errors are:
Code:

main.o: In function `on_changed':
/home/maemo/workspace/helloworld-withDebianSupport/src/main.c:79: undefined reference to `location_gpsd_control_stop'
main.o: In function `start_location':
/home/maemo/workspace/helloworld-withDebianSupport/src/main.c:92: undefined reference to `location_gpsd_control_start'
main.o: In function `main':
/home/maemo/workspace/helloworld-withDebianSupport/src/main.c:198: undefined reference to `location_gpsd_control_get_default'
/home/maemo/workspace/helloworld-withDebianSupport/src/main.c:199: undefined reference to `location_gps_device_get_type'
collect2: ld returned 1 exit status
make[2]: *** [helloworldwithdebiansupport] Error 1
make[2]: Target `all-am' not remade because of errors.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

*** exited with code 2

I can't understand, why the references are not found/defined?!?


I hope that's sufficient information, please let me know if more is needed.

nicolai 2010-04-28 09:01

Re: liblocation, undefiend reference
 
Quote:

Originally Posted by ESmith (Post 631109)
Code:

gcc  -O0 -g  -o helloworldwithdebiansupport  main.o -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgnomevfs-2 -lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0  -pthread -lhildon-1 -lhildonfm -lgtk-x11-2.0 -lgnomevfs-2 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0  -losso -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lglib-2.0
I can't understand, why the references are not found/defined?!?

At least:
Code:

-llocation
nicolai

Andre Klapper 2010-04-28 09:05

Re: liblocation, undefiend reference
 
Quote:

Originally Posted by ESmith (Post 631109)
Code:

gcc  -O0 -g  -o helloworldwithdebiansupport
And the errors are:
Code:

main.o: In function `on_changed':
/home/maemo/workspace/helloworld-withDebianSupport/src/main.c:79: undefined reference to `location_gpsd_control_stop'


What are the exact #include lines in your source file? Are you sure you link to the correct header files for location_gpsd*?

ESmith 2010-04-28 09:05

Re: liblocation, undefiend reference
 
Thanks, Nicolai, that's what I "feel", too. And I have been trying to include this into the gcc-statement.

But I have no idea, how to add it. I assume(d) that ESbox would take care of the necessary libraries to include. If not, how can I add them manually to the compiler statement (in ESbox)?

ESmith 2010-04-28 09:09

Re: liblocation, undefiend reference
 
Quote:

Originally Posted by Andre Klapper (Post 631134)
What are the exact #include lines in your source file? Are you sure you link to the correct header files for location_gpsd*?

Thanks for the quick reply!

Code:

/* Includes */
#include <location/location-gps-device.h>
#include <location/location-gpsd-control.h>
#include <hildon/hildon-program.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkbutton.h>
#include <libosso.h>
#include <string.h>
#include <stdlib.h>
#include "localisation.h"

Leaving the "location"-headers away or modifying them brings up different errors:

Code:

src/main.c:63: error: expected ')' before '*' token
src/main.c:69: error: expected ')' before '*' token
src/main.c:82: error: expected ')' before '*' token
src/main.c: In function 'start_location':
src/main.c:90: error: 'LocationGPSDControl' undeclared (first use in this function)
src/main.c:90: error: (Each undeclared identifier is reported only once
src/main.c:90: error: for each function it appears in.)
src/main.c:90: error: expected expression before ')' token
src/main.c: In function 'main':
src/main.c:188: error: 'LocationGPSDControl' undeclared (first use in this function)
src/main.c:188: error: 'control' undeclared (first use in this function)
src/main.c:189: error: 'LocationGPSDevice' undeclared (first use in this function)
src/main.c:189: error: 'device' undeclared (first use in this function)
src/main.c:197: error: 'LOCATION_TYPE_GPS_DEVICE' undeclared (first use in this function)
src/main.c:200: error: 'LOCATION_METHOD_USER_SELECTED' undeclared (first use in this function)
src/main.c:201: error: 'LOCATION_INTERVAL_DEFAULT' undeclared (first use in this function)
src/main.c:204: error: 'on_error' undeclared (first use in this function)
src/main.c:205: error: 'on_changed' undeclared (first use in this function)
src/main.c:206: error: 'on_stop' undeclared (first use in this function)
make[2]: Leaving directory `/home/maemo/workspace/helloworld-withDebianSupport'
make[1]: Leaving directory `/home/maemo/workspace/helloworld-withDebianSupport'
make[2]: *** [main.o] Error 1
make[2]: Target `all-am' not remade because of errors.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

*** exited with code 2


Joorin 2010-04-28 09:13

Re: liblocation, undefiend reference
 
nicolai beat me to it.

Just as he pointed out, you have no instruction to the linker to look in liblocation for symbols that will satisfy the function calls in your code.

The flag -l means "Add this library to the list of libraries to look for symbols in.".

The flag -L means "Look in this directory for libraries to use while linking.".

So, in this case, the combination
Code:

-L/user/lib -llocation
will instruct the linker to look in /usr/lib for something that matches "liblocation.so.*". In most cases you don't have to supply the "-L/usr/lib" flag since the compiler has been instructed to look there by the people that configured it.

Happy (hacking|linking)! :)


All times are GMT. The time now is 09:26.

vBulletin® Version 3.8.8