Error while compiling mlx90640-library

Hi all. Trying to compile mlx90640-library on the latest raspbian I get the following:

sudo apt-get install libi2c-dev
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen… Fertig
libi2c-dev ist schon die neueste Version (3.1.2-3).
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

===> is already newest version // I2C is enabled …

pi@rpi-touch-1:~/mlx90640-library $ make clean
rm -f test step fbuf interp video
rm -f examples/.o
rm -f examples/lib/
.o
rm -f functions/*.o
rm -f *.o
rm -f *.so
rm -f test
rm -f *.a

pi@rpi-touch-1:~/mlx90640-library $ make I2C_MODE=LINUX
g++ -I. -std=c++11 -std=c++11 -c -o examples/test.o examples/test.cpp
g++ -I. -std=c++11 -fPIC -I headers -shared -c -o functions/MLX90640_API.o functions/MLX90640_API.cpp
g++ -I. -std=c++11 -fPIC -I headers -shared -c -o functions/MLX90640_LINUX_I2C_Driver.o functions/MLX90640_LINUX_I2C_Driver.cpp
In file included from functions/MLX90640_LINUX_I2C_Driver.cpp:24:0:
/usr/include/linux/i2c.h:68:8: error: redefinition of ‘struct i2c_msg’
struct i2c_msg {
^~~~~~~
In file included from functions/MLX90640_LINUX_I2C_Driver.cpp:23:0:
/usr/include/linux/i2c-dev.h:37:8: error: previous definition of ‘struct i2c_msg’
struct i2c_msg {
^~~~~~~
In file included from functions/MLX90640_LINUX_I2C_Driver.cpp:24:0:
/usr/include/linux/i2c.h:131:7: error: redefinition of ‘union i2c_smbus_data’
union i2c_smbus_data {
^~~~~~~~~~~~~~
In file included from functions/MLX90640_LINUX_I2C_Driver.cpp:23:0:
/usr/include/linux/i2c-dev.h:89:7: error: previous definition of ‘union i2c_smbus_data’
union i2c_smbus_data {
^~~~~~~~~~~~~~
functions/MLX90640_LINUX_I2C_Driver.cpp: In function ‘int MLX90640_I2CRead(uint8_t, uint16_t, uint16_t, uint16_t*)’:
functions/MLX90640_LINUX_I2C_Driver.cpp:51:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[0].buf = (__u8*)cmd;
^~~~~~~~~~
functions/MLX90640_LINUX_I2C_Driver.cpp:56:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[1].buf = (__u8*)buf;
^~~~~~~~~~
functions/MLX90640_LINUX_I2C_Driver.cpp: In function ‘int MLX90640_I2CWrite(uint8_t, uint16_t, uint16_t)’:
functions/MLX90640_LINUX_I2C_Driver.cpp:93:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[0].buf = (__u8*)cmd;
^~~~~~~~~~
: die Regel für Ziel „functions/MLX90640_LINUX_I2C_Driver.o“ scheiterte
make: *** [functions/MLX90640_LINUX_I2C_Driver.o] Fehler 1

Any ideas where to look next?

Regards,

Torsten.

Try commenting out #include <linux/i2c.h> in functions/MLX90640_LINUX_I2C_Driver.cpp - I don’t think both of those includes are needed.

I have a similar problem and more:

root@RPi3AP:/temp/mlx90640-library# uname -a
Linux RPi3AP 4.14.97-v7+ #1197 SMP Mon Feb 4 21:13:29 GMT 2019 armv7l GNU/Linux
root@RPi3AP:/temp/mlx90640-library# make clean
rm -f test step fbuf interp video
rm -f examples/.o
rm -f examples/lib/
.o
rm -f functions/.o
rm -f .o
rm -f .so
rm -f test
rm -f .a
root@RPi3AP:/temp/mlx90640-library# make I2C_MODE=LINUX
g++ -I. -std=c++11 -std=c++11 -c -o examples/test.o examples/test.cpp
g++ -I. -std=c++11 -fPIC -I headers -shared -c -o functions/MLX90640_API.o functions/MLX90640_API.cpp
g++ -I. -std=c++11 -fPIC -I headers -shared -c -o functions/MLX90640_LINUX_I2C_Driver.o functions/MLX90640_LINUX_I2C_Driver.cpp
ar rcs libMLX90640_API.a functions/MLX90640_API.o functions/MLX90640_LINUX_I2C_Driver.o
ranlib libMLX90640_API.a
g++ -L/home/pi/mlx90640-library examples/test.o libMLX90640_API.a -o test
g++ -I. -std=c++11 -std=c++11 -c -o examples/step.o examples/step.cpp
g++ -L/home/pi/mlx90640-library examples/step.o libMLX90640_API.a -o step
g++ -I. -std=c++11 -std=c++11 -c -o examples/fbuf.o examples/fbuf.cpp
cc -c -o examples/lib/fb.o examples/lib/fb.c
g++ -L/home/pi/mlx90640-library examples/fbuf.o examples/lib/fb.o libMLX90640_API.a -o fbuf
g++ -I. -std=c++11 -std=c++11 -c -o examples/interp.o examples/interp.cpp
g++ -std=c++11 -c -o examples/lib/interpolate.o examples/lib/interpolate.c
g++ -L/home/pi/mlx90640-library examples/interp.o examples/lib/interpolate.o examples/lib/fb.o libMLX90640_API.a -o interp
g++ -I. -std=c++11 -std=c++11 -c -o examples/video.o examples/video.cpp
examples/video.cpp: In function ‘void video_encode_start(const char
, int, AVCodecID)’:
examples/video.cpp:118:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
if (video_avstream->codec == NULL) {
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:118:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
if (video_avstream->codec == NULL) {
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:118:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
if (video_avstream->codec == NULL) {
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:124:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
c = video_avstream->codec;
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:124:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
c = video_avstream->codec;
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:124:25: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
c = video_avstream->codec;
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp: In function ‘void video_encode_frame(int)’:
examples/video.cpp:207:11: warning: ‘int avcodec_encode_video2(AVCodecContext
, AVPacket
, const AVFrame
, int*)’ is deprecated -Wdeprecated-declarations]
ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
^~~~~~~~~~~~~~~~~~~~~
In file included from examples/video.cpp:15:0:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:5333:5: note: declared here
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
^~~~~~~~~~~~~~~~~~~~~
examples/video.cpp:207:60: warning: ‘int avcodec_encode_video2(AVCodecContext*, AVPacket*, const AVFrame*, int*)’ is deprecated -Wdeprecated-declarations]
ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
^
In file included from examples/video.cpp:15:0:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:5333:5: note: declared here
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
^~~~~~~~~~~~~~~~~~~~~
examples/video.cpp:221:3: warning: ‘void av_free_packet(AVPacket*)’ is deprecated [-Wdeprecated-declarations]
av_free_packet(&pkt);
^~~~~~~~~~~~~~
In file included from examples/video.cpp:15:0:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:4483:6: note: declared here
void av_free_packet(AVPacket *pkt);
^~~~~~~~~~~~~~
examples/video.cpp:221:22: warning: ‘void av_free_packet(AVPacket*)’ is deprecated [-Wdeprecated-declarations]
av_free_packet(&pkt);
^
In file included from examples/video.cpp:15:0:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:4483:6: note: declared here
void av_free_packet(AVPacket *pkt);
^~~~~~~~~~~~~~
examples/video.cpp: In function ‘void video_encode_end()’:
examples/video.cpp:242:48: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
av_freep(&avFormatContext->streams[i]->codec);
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:242:48: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
av_freep(&avFormatContext->streams[i]->codec);
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp:242:48: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
av_freep(&avFormatContext->streams[i]->codec);
^~~~~
In file included from examples/video.cpp:21:0:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
AVCodecContext *codec;
^~~~~
examples/video.cpp: In function ‘void video_encode_start(const char*, int, AVCodecID)’:
examples/video.cpp:195:49: warning: ignoring return value of ‘int avformat_write_header(AVFormatContext*, AVDictionary**)’, declared with attribute warn_unused_result [-Wunused-result]
avformat_write_header(avFormatContext, &params);
^
g++ -L/home/pi/mlx90640-library examples/video.o examples/lib/fb.o libMLX90640_API.a -o video -lavcodec -lavutil -lavformat
examples/video.o: In function pulse()': video.cpp:(.text+0xc94): undefined reference tobcm2835_gpio_write’
video.cpp:(.text+0xcc8): undefined reference to bcm2835_gpio_write' examples/video.o: In functionmain’:
video.cpp:(.text+0xd10): undefined reference to bcm2835_init' video.cpp:(.text+0xd1c): undefined reference tobcm2835_gpio_fsel’
video.cpp:(.text+0x111c): undefined reference to `bcm2835_close’
collect2: error: ld returned 1 exit status
Makefile:43: recipe for target ‘video’ failed
make: *** [video] Error 1
root@RPi3AP:/temp/mlx90640-library#

@janeksz quick fix, find this line in the Makefile:

$(CXX) -L/home/pi/mlx90640-library $^ -o $@ $(I2C_LIBS) -lavcodec -lavutil -lavformat

And add -lbcm2835 to the end.

Or, right at the very top of the Makefile find:

ifeq ($(I2C_MODE), LINUX)
	I2C_LIBS =
endif

And remove those lines.

The issue is that it’s assuming the bcm2835 library is used only for the non-generic I2C_MODE and isn’t linking against it when you specify I2C_MODE=LINUX. For the video example this isn’t the case, since it uses bcm2835 functions to pulse a GPIO pin as an oscilloscope trigger- redundant code I need to remove.

1 Like

Thanks,much appreciate your work and help. I’m trying to visualize it in nodered. Have you done anything similar or can you give me some hints? Cheers, Jan

Hi! I ran into the exact same problem as GobLin77. I tried the solution you offered and some of the errors went away. Yet, 3 of them still prevent me from compiling:

functions/MLX90640_LINUX_I2C_Driver.cpp: In function ‘int MLX90640_I2CRead(uint8_t, uint16_t, uint16_t, uint16_t*)’:
functions/MLX90640_LINUX_I2C_Driver.cpp:51:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[0].buf = (__u8*)cmd;
^~~~~~~~~~
functions/MLX90640_LINUX_I2C_Driver.cpp:56:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[1].buf = (__u8*)buf;
^~~~~~~~~~
functions/MLX90640_LINUX_I2C_Driver.cpp: In function ‘int MLX90640_I2CWrite(uint8_t, uint16_t, uint16_t)’:
functions/MLX90640_LINUX_I2C_Driver.cpp:93:27: error: invalid conversion from ‘__u8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
i2c_messages[0].buf = (__u8*)cmd;

Any suggestions on how to proceed? Thanks in advance.

Andy.-