Don't compile a project in linux by adding other libraries. How is it done?


#1

Hi, I need to compile some external libraries in a project of the linux client of thinger. io.
The library used is the same as in this case: Raspberry Pi & Linux Updating Cloud Data C++

I have tried to add the libraries and with cmake recompile the whole project but it doesn’t work.
Can someone help me?
My code is similar to the back case:

#include “thinger/thinger.h”
#include “wunderground/wunderground.hpp”
#include <ostream
#include <string

#define USER_ID “xx”
#define DEVICE_ID “xx”
#define DEVICE_CREDENTIAL “xx”

using namespace std;

string ApiKey="xxx";
wunderground::Conditions weather(ApiKey);
weather.loadData("zagreb","croatia");

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

thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);

thing[“data”] >> [=weather](pson& out){
out[“temp”] = weather.getCondition(“temperature”);
};

while(true)
{
    thing.handle();
    thing.stream(thing["data"]);
}
return 0;

}

I’m trying to simulate what a temperature sensor reading would look like, so that in the future I can switch to a real sensor.

I’m adding to CmakeLists.txt this, and the folder wunderground is in the folder /src:

> # Support for wunder on Raspberry
> if(RASPBERRY)
>     find_package(wunderground)
>     if(WiringPi_FOUND)
>         include_directories(${wunderground_INCLUDE_DIR})
>         list(APPEND ADDITIONAL_LIBS ${wunderground_LIBRARIES})
>     endif()
> endif()

Errors:

In function ‘int main(int, char**)’:
/home/r/Escritorio/raspb/src/main.cpp:60:22: error: expected ‘,’ before ‘weather’
   thing["data"] >> [=weather](pson& out){
                      ^
/home/r/Escritorio/raspb/src/main.cpp:60:22: warning: explicit by-copy capture of ‘weather’ redundant with by-copy capture default
/home/r/Escritorio/raspb/src/main.cpp: In lambda function:
/home/r/Escritorio/raspb/src/main.cpp:61:55: error: passing ‘const wunderground::Conditions’ as ‘this’ argument discards qualifiers [-fpermissive]
       out["temp"] = weather.getCondition("temperature");

/home/r/Escritorio/raspb/src/main.cpp: In function ‘int main(int, char**)’:
/home/r/Escritorio/raspb/src/main.cpp:60:17: error: no match for ‘operator>>’ (operand types are ‘thinger::thinger_resource’ and ‘main(int, char**)::<lambda(protoson::pson&)>’)
   thing["data"] >> [=weather](pson& out)
.
.
.
.
.

The line numbers are not the same because I have deleted many comments.

Thanks for your help. :sweat::sweat: @alvarolb


#2

This definition seems to be wrong. It should be:

thing["data"] >> [](pson& out){
   out["temp"] = weather.getCondition("temperature");
};

#3

I tried so many things that in the end it stayed that way.
What I don’t know is how to add the wunderground library to the program so that it can be compiled with the cmake or runing ./run.sh.

for example, if I use the example web code and I add the wunderground library:

#include "thinger/thinger.h"
#include "wunderground/wunderground.hpp"

#define USER_ID             "xxx"
#define DEVICE_ID           "xxx"
#define DEVICE_CREDENTIAL   "xxx"

using namespace std;

int main(int argc, char *argv[])
{
    thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);

    string ApiKey="xxxxx";
    wunderground::Conditions weather(ApiKey);
    weather.loadData("zagreb","croatia");

    // define thing resources here. i.e, this is a sum example
    thing["sum"] = [](pson& in, pson& out){
        out["result"] = (int) in["value1"] + (int) in["value2"];
    };

    thing.start();
    return 0;
}

The terminal:

r@r-VirtualBox:~/Escritorio/Linux-Client-master$ ./run.sh 
-- OpenSSL Version: 1.0.2g
-- Configuring done
-- Generating done
-- Build files have been written to: /home/r/Escritorio/Linux-Client-master/build
Scanning dependencies of target thinger
[ 50%] Building CXX object CMakeFiles/thinger.dir/src/main.cpp.o
[100%] Linking CXX executable thinger
CMakeFiles/thinger.dir/src/main.cpp.o: En la función `main':
main.cpp:(.text.startup+0x173): referencia a `wunderground::Conditions::Conditions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' sin definir
main.cpp:(.text.startup+0x1ce): referencia a `wunderground::Conditions::loadData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' sin definir
main.cpp:(.text.startup+0x3251): referencia a `vtable for wunderground::Conditions' sin definir
collect2: error: ld returned 1 exit status
CMakeFiles/thinger.dir/build.make:96: fallo en las instrucciones para el objetivo 'thinger'
make[3]: *** [thinger] Error 1
CMakeFiles/Makefile2:67: fallo en las instrucciones para el objetivo 'CMakeFiles/thinger.dir/all'
make[2]: *** [CMakeFiles/thinger.dir/all] Error 2
CMakeFiles/Makefile2:79: fallo en las instrucciones para el objetivo 'CMakeFiles/thinger.dir/rule'
make[1]: *** [CMakeFiles/thinger.dir/rule] Error 2
Makefile:118: fallo en las instrucciones para el objetivo 'thinger'
make: *** [thinger] Error 2
./run.sh: línea 6: ./thinger: No existe el archivo o el directorio

:pensive::pensive: I need compile this for simulating data adquisition

Thanks a lot for your time.


#4

Hi, this problem is not just related with Thinger.io, and it seems that your CmakeLists.txt it is not adding the appropriate libraries when linking. If you are using the compiler over virtual box (and not just a raspberry pi, as your log states), then this code is not doing anything.

Support for wunder on Raspberry

if(RASPBERRY)
find_package(wunderground)
if(WiringPi_FOUND)
include_directories(${wunderground_INCLUDE_DIR})
list(APPEND ADDITIONAL_LIBS ${wunderground_LIBRARIES})
endif()
endif()

You should just try to remove the beginning if() and endif(). Then you may find other errors if the wunderground is not installed, the cmake module is not available, etc. Also the WiringPi_FOUND does not apply here.