I am relatively new to C++, but have come from Python and C.
I am using an SDK for a lidar sensor. I have 5 main files that are involved; SDK.h
, SDK.cpp
, setup.h
, setup.cpp
and main.cpp
.
A class is defined within the SDK.
rplidar.h
class RPlidarDriver{
public:
static RPlidarDriver * CreateDriver(_u32 drivertype = DRIVER_TYPE_SERIALPORT);
// more code
}
main.cpp
#include <iostream>
#include "rplidar.h"
#include "setup.h"
using namespace std;
using namespace rp::standalone::rplidar;
int main()
{
//code
RPlidarDriver* lidar = RPlidarDriver::CreateDriver(DRIVER_TYPE_SERIALPORT);
start_reading(lidar, scanMode);
//code
}
setup.cpp
#include "setup.h"
#include "rplidar.h"
using namespace std;
using namespace rp::standalone::rplidar;
void start_reading(RPlidarDriver* driver, const char* scanMode)
{
//start motor
driver->startMotor();
//more code...
}
setup.h
#include "rplidar.h"
using namespace rp::standalone::rplidar;
namespace setup
{
void start_reading(RPlidarDriver* driver, const char* scanMode);
}
However I get this error
main.obj : error LNK2019: unresolved external symbol "void __cdecl setup::start_reading(class rp::standalone::rplidar::RPlidarDriver *,char const *)" (?start_reading@setup@@YAXPAVRPlidarDriver@rplidar@standalone@rp@@PBD@Z) referenced in function _main
I also get the same error for other functions that I try to use the object as a parameter.
If I put the function in setup.cpp
into main.cpp
, it compiles easily. I tried to implement &
and use the parameter as a reference instead, but not luck.