Reputation: 323
We are having a problem getting libxively working on our Raspberry Pi. We're programming in C with Geany, and want to get xively to work.But we are getting numerous errors. We followed several tutorials but couldn't figure out what's wrong.
Here is part of our main.c. We do have the feedID and API key in our code, of course.
#include </home/pi/libxively/src/libxively/xively.h>
#include </home/pi/libxively/src/libxively/xi_helpers.h>
#include </home/pi/libxively/src/libxively/xi_err.h>
#include <stdio.h>
#include <string.h>
#define XI_FEED_ID ---// set Xively Feed ID (numerical, no quoutes
#define XI_API_KEY "---" // set Xively API key (double-quoted string)
int xively();
int main(int argc, char **argv)
{xively();}
int xively()
{
xi_feed_t feed;
memset( &feed, NULL, sizeof( xi_feed_t ) );
feed.feed_id = XI_FEED_ID;
feed.datastream_count = 2;
feed.datastreams[0].datapoint_count = 1;
xi_datastream_t* foo_datastream = &feed.datastreams[0];
strcpy( foo_datastream->datastream_id, "foo" );
xi_datapoint_t* current_foo = &foo_datastream->datapoints[0];
feed.datastreams[1].datapoint_count = 1;
xi_datastream_t* bar_datastream = &feed.datastreams[1];
strcpy( bar_datastream->datastream_id, "bar" );
xi_datapoint_t* current_bar = &bar_datastream->datapoints[0];
// create the xively library context
xi_context_t* xi_context
= xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
// check if everything works
if( xi_context == NULL )
{
return -1;
}
xi_set_value_str( current_bar, "unknown" );
xi_set_value_f32( current_foo, 0.123 );
xi_feed_update(xi_context, &feed);
return 0;
}
We think something is wrong with the makefile, so here you go:
#This sample makefile has been setup for a project which contains the following files: main
#Change output_file_name.a to your desired executable filename
#Set all your object files (the object files of all the .c files in yourproject, e.g. main
OBJ = main.o
#Set any dependant header files so that if they are edited they cause a complete re-compile
DEPS = main.h
#Any special libraries you are using in your project
LIBS = -lrt -lwiringPi -L$(HOME)/pi/libxively/src/libxively -L/root/libxively/src/libxively -dxively
#we did try -lxively but that didn't work either
#Set any compiler flags you want to use
CFLAGS = -lrt
#Set the compiler you are using ( gcc for C or g++ for C++ )
CC = gcc
#Set the filename extension of your C files
EXTENSION = .c
#Define a rule that applies to all files ending in the .o suffix, which says ...
%.o: %$(EXTENSION) $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
#Combine them into the outputfile
#Set your desired exe output filename here
sensortest.a: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
#Cleanup
.PHONY: clean
clean:
srm -f *.o *~ core *~
When we compile it we get the following errors:
Upvotes: 2
Views: 276
Reputation: 2016
The errors shown in the picture are:
First error, use '0' (zero!), not NULL. NULL is for pointers, you want to set the memory to zero, use a zero. That'll fix that one.
As for the other error, you're missing a -lxively
somewhere, ... looking...
From your Makefile
:
#Any special libraries you are using in your project
LIBS = -lrt -lwiringPi -L$(HOME)/pi/libxively/src/libxively -L/root/libxively/src/libxively -dxively
#we did try -lxively but that didn't work either
No idea what -dxively
is supposed to do, no such option for ld
or gcc
... I see your comment about -lxively
not working.
Where is the libxively.so.??
file? In the libxively/src/libxively
subdirectory? You'll have much better luck if you actually install the library in it's proper place (umm, /usr/lib
or /lib
or ... gosh! somewhere!) That would make it easier, but in any case, if the library has been properly compiled, figure out where it is, and put the proper PATH in the -L
option. You've got two -L
's there, which one is it? the pi
user typically cannot read anything in /root
home directory, that's not going to work, can be removed.
Once you have the libxively.so
file compiled and located, with the proper path in an -L
option in your Makefile
, then the -lxively
option should work as expected.
Without some more information about where the file is located, if it's compiled successfully, and an update on the error messages, can't do too much more to help.
EDIT:
We're going to rebuild your Makefile:
# New and improved Makefile (remember about the TABS vs SPACES here!)
#
XIVELY_OBJ_PATH=$(HOME)/libxively/obj
#
# Any special libraries you are using in your project
LIBS=-lrt -lwiringPi
#
# Now add all the pesky .o files
LIBS+=$(wildcard $(XIVELY_OBJ_PATH)/*.o)
LIBS+=$(wildcard $(XIVELY_OBJ_PATH)/io/posix/*.o)
#
LDFLAGS=
#
# We love the new standard
CFLAGS+=-std=c99
#
# debugging symbols always good
CFLAGS+=-g
#
CC=gcc
#
.PHONY: all clean
#
all: sensortest
#
sensortest: main.c main.h
$(CC) $(CFLAGS) -c -o [email protected] $<
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ [email protected] $(LIBS)
#
clean:
rm -f sensortest *.o
(We discussed this over chat and figured it out)
Upvotes: 3