Skip to main content
Associate II
June 18, 2024
Question

Compile VL6180X API in c

  • June 18, 2024
  • 2 replies
  • 2257 views

Hello,
I'm trying to get a VL6180X sensor to work.
I've downloaded the latest API: en.VL6180_API_V1.3.0.zip
My goal is to make the sensor work in I2c on a Raspberry PI in the c or c++ language.
But I can't compile my code, or rather compile the api into a library.
Where can I find an example of a makefile or command to do this?

Thanks for your help.

2 replies

Andrew Neil
Super User
June 18, 2024

Did you mean to ask a question?

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

EDIT:  OP has now been updated to include a question

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
June 18, 2024

@SCADE wrote:

But I can't compile my code, or rather compile the api into a library.


What problem(s), exactly, are you facing?

What have you tried so far?

Again, please see:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SCADEAuthor
Associate II
June 18, 2024

Ok so here is my test.cpp file :

#include <iostream>
#include <unistd.h>
#include "vl6180_api.h"

int main()
{
 VL6180Dev_t tof = 0x29;

 VL6180_WaitDeviceBooted(tof);
 VL6180_InitData(tof);
 VL6180_Prepare(tof);

 for (size_t i = 0; i < 10; i++)
 {

 VL6180_RangeData_t rangeData;
 VL6180_RangePollMeasurement(tof, &rangeData);

 printf("Range: %d\n", rangeData.range_mm);
 }

 VL6180_FilterSetState(tof, 1);

 return 0;
}

file structure : 
api_vl6180x_1.4.0/
api_vl6180x_1.4.0/config
api_vl6180x_1.4.0/config/vl6180_cfg.h
api_vl6180x_1.4.0/core
api_vl6180x_1.4.0/core/inc
api_vl6180x_1.4.0/core/inc/vl6180_def.h
api_vl6180x_1.4.0/core/inc/vl6180_api.h
api_vl6180x_1.4.0/core/src
api_vl6180x_1.4.0/core/src/vl6180_api.c
api_vl6180x_1.4.0/platform
api_vl6180x_1.4.0/platform/template
api_vl6180x_1.4.0/platform/template/vl6180_platform.h
api_vl6180x_1.4.0/platform/template/vl6180_types.h
api_vl6180x_1.4.0/platform/cci-i2c
api_vl6180x_1.4.0/platform/cci-i2c/vl6180_i2c.c
api_vl6180x_1.4.0/platform/cci-i2c/vl6180_i2c.h

and finally compile command :
g++ -o test test.cpp api_vl6180x_1.4.0/core/src/*.c api_vl6180x_1.4.0/platform/cci-i2c/*.c -I api_vl6180x_1.4.0/core/inc/ -I api_vl6180x_1.4.0/platform/template/ -I api_vl6180x_1.4.0/config/ -lwiringPi

Error :
/usr/bin/ld: /tmp/ccnVF5wY.o: in function `VL6180_WaitDeviceBooted':
vl6180_api.c:(.text+0x6c): undefined reference to `VL6180_RdByte' ...................................... 

Andrew Neil
Super User
June 18, 2024

@SCADE wrote:

Error :
/usr/bin/ld: /tmp/ccnVF5wY.o: in function `VL6180_WaitDeviceBooted':
vl6180_api.c:(.text+0x6c): undefined reference to `VL6180_RdByte' ...................................... 


"undefined reference" is a linker error.

It means that you have omitted to provide a definition of that function - either as source code, or as a pre-built binary library.

Probably, you have #included a header which just declares that function (ie, just provides a prototype) - hence the compiler is happy - but haven't added the necessary source or pre-built binary library to your project - so the link fails.

 

#UdefinedReference

 

EDIT:

Looks like these are the docs you need:

AndrewNeil_0-1718704772243.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.