Static library linking using Waf

Hi,

I hope this is the right place to ask.

I’m trying to add a new rangefinder, which uses a proprietary static library. Creating a new dummy rangefinder under libraries/AP_Rangefinder works fine, as does linking it to the existing code so it can be selected, but when I modify the code to call the static library I’m getting compilation errors.

The code includes:

  • libraries/AP_RangeFinder/AP_RangeFinder_ISA500.cpp:
...
#include <AP_HAL/AP_HAL.h>
#include "AP_RangeFinder_ISA500.h"
#include <AP_SerialManager/AP_SerialManager.h>
#include "ISA500/IslComms.h"
#include <GCS_MAVLink/GCS.h>
...
AP_RangeFinder_ISA500::AP_RangeFinder_ISA500(RangeFinder::RangeFinder_State &_state, AP_SerialManager &serial_manager) :
AP_RangeFinder_Backend(_state) {
gcs().send_text(MAV_SEVERITY_INFO, "ISA library version: %d ", IslComms::GetVersion());
...
  • libraries/AP_RangeFinder/AP_RangeFinder_ISA500.h:
...
#include "RangeFinder.h"
#include "RangeFinder_Backend.h"
#include "ISA500/IslComms.h"
...
  • libraries/AP_RangeFinder/ISA500/IslComms.h:
...
class IslComms
{
public:
IslComms();
~IslComms();
static uint8_t* GetVersion();
static void Run(int32_t deltaMs);
static void ProcessNewData(IslDevice* device, uint8_t* data, int32_t length);
static IslDevice* AddDevice(IslDevice::devicePid_t type, void(*TransmitData)(uint8_t* data, int32_t length));
static IslDevice* AddMultidropDevice(IslDevice::devicePid_t type, IslDevice* device);
static void DeleteDevice(IslDevice* device);
};
...
  • libraries/AP_RangeFinder/ISA500/IslComms.a - a static library, that I have no access to the code for

When I compile, it continues for a while and then gives a number of errors of the form:

/home/andrew/ardupilot/build/px4-v2/lib/bin/libarducopter.a(AP_RangeFinder_ISA500.cpp.0.o): In function `AP_RangeFinder_ISA500::AP_RangeFinder_ISA500(RangeFinder::RangeFinder_State&, AP_SerialManager&)':
/home/andrew/ardupilot/build/px4-v2/../../libraries/AP_RangeFinder/AP_RangeFinder_ISA500.cpp:55: undefined reference to `IslComms::GetVersion()'

(Where ‘IslComms::GetVersion()’ is a function in IslComms.h and IslComms.a; each of the errors corresponds to a different call to a library function)

Things I’ve tried:

  • Editing wscript to add the following in def configure(cfg):
cfg.env.append_value("LINKFLAGS", ["-Llibraries/AP_RangeFinder/ISA500/", "-l:IslComms.a"])
  • Editing Tools/ardupilotwaf/boards.py to add the following to env.CXXFLAGS:
class px4(Board):
...
def configure_env(self, cfg, env):
...
env.CXXFLAGS += [
...
'-L/home/andrew/ardupilot/libraries/AP_RangeFinder/ISA500',
'-l:IslComms.a',
]
  • Looking through various other build files to see if I can find where I should be linking it

But nothing has changed the result.

In case it helps, I’m using ArduCopter on a Pixhawk. If I comment out the calls to the static library then everything seems to compile fine.

Does anyone have any suggestions for things I can try?

Many thanks

Make sure you the static library has the symbol in it?

Try supplying a completely bogus filename in cfg.env.append_value and make
sure it dies.

Also, please be aware of your obligations in terms of supply of source
code to anything linked in this way to a GPLv3 project to anybody who
gets the resulting binary.

Peter

[45.png]
AATSMD Andrew
May 3

Hi,

I hope this is the right place to ask.

I¢m trying to add a new rangefinder, which uses a proprietary static
library. Creating a new dummy rangefinder under libraries/AP_Rangefinder
works fine, as does linking it to the existing code so it can be selected,
but when I modify the code to call the static library I¢m getting
compilation errors.

The code includes:

  • libraries/AP_RangeFinder/AP_RangeFinder_ISA500.cpp:


#include <AP_HAL/AP_HAL.h>
#include “AP_RangeFinder_ISA500.h”
#include <AP_SerialManager/AP_SerialManager.h>
#include “ISA500/IslComms.h”
#include <GCS_MAVLink/GCS.h>

AP_RangeFinder_ISA500::AP_RangeFinder_ISA500(RangeFinder::RangeFinder_State
&_state, AP_SerialManager &serial_manager) :
AP_RangeFinder_Backend(_state) {
gcs().send_text(MAV_SEVERITY_INFO, "ISA library version: %d ", IslComms::Get
Version());

  • libraries/AP_RangeFinder/AP_RangeFinder_ISA500.h:


#include “RangeFinder.h”
#include “RangeFinder_Backend.h”
#include “ISA500/IslComms.h”

  • libraries/AP_RangeFinder/ISA500/IslComms.h:


class IslComms
{
public:
IslComms();
~IslComms();
static uint8_t* GetVersion();
static void Run(int32_t deltaMs);
static void ProcessNewData(IslDevice* device, uint8_t* data, int32_t length)
;
static IslDevice* AddDevice(IslDevice::devicePid_t type, void(TransmitData)
(uint8_t
data, int32_t length));
static IslDevice* AddMultidropDevice(IslDevice::devicePid_t type, IslDevice*
device);
static void DeleteDevice(IslDevice* device);
};

  • libraries/AP_RangeFinder/ISA500/IslComms.a - a static library, that I
    have no access to the code for

When I compile, it continues for a while and then gives a number of errors
of the form:

/home/andrew/ardupilot/build/px4-v2/lib/bin/libarducopter.a(AP_RangeFinder_I
SA500.cpp.0.o): In function AP_RangeFinder_ISA500::AP_RangeFinder_ISA500(Ra ngeFinder::RangeFinder_State&, AP_SerialManager&)': /home/andrew/ardupilot/build/px4-v2/../../libraries/AP_RangeFinder/AP_RangeF inder_ISA500.cpp:55: undefined reference to IslComms::GetVersion()’

(Where ¡IslComms::GetVersion()¢ is a function in IslComms.h and IslComms.a;
each of the errors corresponds to a different call to a library function)

Things I¢ve tried:

  • Editing wscript to add the following in def configure(cfg):

cfg.env.append_value(“LINKFLAGS”, [“-Llibraries/AP_RangeFinder/ISA500/”, “-l
:IslComms.a”])

  • Editing Tools/ardupilotwaf/boards.py to add the following to
    env.CXXFLAGS:

class px4(Board):

def configure_env(self, cfg, env):

env.CXXFLAGS += [

‘-L/home/andrew/ardupilot/libraries/AP_RangeFinder/ISA500’,
‘-l:IslComms.a’,
]

  • Looking through various other build files to see if I can find where I
    should be linking it

But nothing has changed the result.

In case it helps, I¢m using ArduCopter on a Pixhawk. If I comment out the
calls to the static library then everything seems to compile fine.

Does anyone have any suggestions for things I can try?

Many thanks


Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.

Peter Barker | Programmer,Sysadmin,Geek.
pbarker@barker.dropbear.id.au | You need a bigger hammer.
:: It’s a hack! Expect underscores! - Nigel Williams

Hi,

Thanks for getting back to me so quickly.

Make sure you the static library has the symbol in it?

It seems to:

$ nm build/px4-v2/libraries/AP_RangeFinder/AP_RangeFinder_ISA500.cpp.0.o | grep "GetVersion"
         U _ZN8IslComms10GetVersionEv
$ nm libraries/AP_RangeFinder/ISA500/IslComms.a | grep "GetVersion"
00000029 T _ZN8IslComms10GetVersionEv

Try supplying a completely bogus filename in cfg.env.append_value and make sure it dies.

Changing to:

cfg.env.append_value("LINKFLAGS", ["-Llibraries/AP_RangeFinder/ISA500/", "-l:foobar.a"])

How interesting - there’s no change…

This presumably means that I’m setting the link flags in the wrong place. Have you any recommendations on where it should be being set?

Also, please be aware of your obligations in terms of supply of source code to anything linked in this way to a GPLv3 project to anybody who gets the resulting binary.

Yes - thanks for the warning, but we’re not planning to release this build (it’s purely for an internal system).

Thanks for your help!