2

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: A screenshot of the errors we get when compiling main.c

dirkk
  • 6,160
  • 5
  • 33
  • 51
Kailayla
  • 323
  • 5
  • 15

1 Answers1

3

The errors shown in the picture are:

  • main.c:101:5: warning: passing argument 2 of 'memset' makes integer from pointer without a cast
  • compilation failed (undefined references to 'xi_....' stuff.

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 $@.o $<
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.o $(LIBS)
#
clean:
    rm -f sensortest *.o

(We discussed this over chat and figured it out)

lornix
  • 1,946
  • 17
  • 14
  • We followed the instructions on the xively website. We got no .so file, only normal .o files. We found a different question here on stackoverflow where was given the option to point to a directory what we did and then use the -d option to include it. We tried that like in the given code above. We tried several other things to point to a file, like the .a and .o files. But no luck. If we try -lxively we get the error: : no such file or directory. with -d, it compiles normally with your answer but gives undefined references. – Kailayla Jul 01 '14 at 12:29
  • Hmmm, the undefined references are because gcc/ld can't find the library needed to complete linking the program. Hmmmmm... – lornix Jul 01 '14 at 12:31
  • (sorry for the double post, pressed enter and cant edit comments) We tried to find .so files on our rpi, but cant find the file. we tried searching in /usr/lib, but only the other libraries showed up. Maybe there is something wrong with the instructions of xively itself or must we take some others steps that aren't documentated. We are completly stuck at this point. – Kailayla Jul 01 '14 at 12:37
  • I pulled the library from their git repo... doesn't take long to compile! And no, no *.so files, just *.o. The *.o files are located in the `obj` subdir, try using a path pointing there: `-L$(HOME)/pi/libxively/obj`, there's nothing in the `src` path that will help. – lornix Jul 01 '14 at 12:43
  • Alright, using your path we now have less errors, but still one: /usr/bin/ld: cannot find -lxively We now have: `LIBS = -lrt -lwiringPi -L$(HOME)/pi/libxively/obj -lxively` in our makefile – Kailayla Jul 01 '14 at 12:51
  • Yeah, just realized, remove the `-lxively` bit, since you don't have a `library`, but a bunch of object files to link in. – lornix Jul 01 '14 at 12:52
  • We are still getting the undefined reference to 'xi_...' errors We tried linking all the single .o files but that didn't work – Kailayla Jul 01 '14 at 13:07
  • Drat! Can't chat. The `-L` path should cause the linker to link the *.o files as needed. Towards the end of your Makefile: `sensortest.a: $(OBJ)` `$(CC) -o $@ $^ $(CFLAGS) $(LIBS)`. Move the `$(LIBS)` bit before the `-o` option. `$(CC) $(LIBS) -o $@ $^ $(CFLAGS)` – lornix Jul 01 '14 at 13:14
  • Libraries are sensitive to WHERE they're declared on the command line, it's a quirk. Wish could chat..... grrrr. – lornix Jul 01 '14 at 13:16
  • Still no luck :( We tried it, still unknown references. We tried several things: removing all the seperate files, only linking the folder, we tried to put the .o files in the `obj=` area(which gave us: `make ***: no rule to make target home/pi/pi/libxively/obj' needed by sensortest.a' Stop`. We tried to link every single .o file in the obj folder. Still getting undefined references. We also tried adding -f flag, which solved the problem of the no rule on pc, but the rpi works different appereantly It's quite a shame we are stuck as this is the only possiblity for us :c – Kailayla Jul 01 '14 at 13:21
  • I have an idea how to fix, but requires more direct interaction. Chat is being recalcitrant! Your Makefile is somewhat odd. – lornix Jul 01 '14 at 13:24
  • Yeah I think I just read I need 20 rep to chat or something dammit – Kailayla Jul 01 '14 at 13:27
  • I would recommend replacing `-lxively` with `${LIBXIVELY_DIR}/obj/libxively.a`. Otherwise you can try `-L${LIBXIVELY_DIR}/obj/ -lxively` and it might work, but I never tested that. – errordeveloper Jul 02 '14 at 08:17