-1

I hope someone can help me as I'm not that experienced in managing the integration of *.h files from external projects in my own work:

Based the sample code provided by the sumo developers to set up a sumo instance in C++, Sumo Libtraci example here, I simply want to connect to an existing SUMO instance as one of two client.

This source tries to connect to an existing server and it seems to be successful/the right way to go Connect to traci Multi client system). Here's the code:

First starting simulation: sumo --remote-port 4001 --num-clients 2 -c config_file.sumocfg

"After starting the simulation I'm trying to connect from two traci client using the code below:"

`#include <libsumo/libtraci.h>

using namespace libtraci;
int main () {
Simulation::init(4001,21,"localhost");
Simulation::setOrder(3);
for (int i = 0; i < 500000; i++) {
Simulation::step();
}
Simulation::close();
return 0;
}

Now, I think I have an issue in my Eclipse C++ environment as I try to build the following code:

#include <iostream>
#include <libsumo/libtraci.h>

using namespace libtraci;

int main(int argc, char* argv[]) {
Simulation::init();
Simulation::setOrder(2);

for (int i=0; i<50; i++)
{
    Simulation::step();
}
Simulation::close();
return 0;
}

I get the following errors:

C:\Users\Lukas\eclipse-ws\Test\Debug/../libsumo/Test.cpp:25: undefined reference to  `libtraci::Simulation::init(int, int, std::__cxx11::basic_string<char,   std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char,  std::char_traits<char>, std::allocator<char> > const&, _iobuf*)'
C:\Users\Lukas\eclipse-ws\Test\Debug/../libsumo/Test.cpp:26: undefined reference to `libtraci::Simulation::setOrder(int)'
C:\Users\Lukas\eclipse-ws\Test\Debug/../libsumo/Test.cpp:30: undefined reference to `libtraci::Simulation::step(double)'
C:\Users\Lukas\eclipse-ws\Test\Debug/../libsumo/Test.cpp:32: undefined reference to `libtraci::Simulation::close(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

I wonder whether this is a typical compiler/linker error which I don't see as I don't have lot of experience in linking together external .h files for own projects. I provided the root folder of libsumo (in libsumo/Simulation.h "init", "setOrder" and "step" function are listed) to my g++ compiler and linker. And based on the errors my systems seems to know the functions very well. But maybe someone can explain to me what is "undefined reference" in this case.

Additionally: Do I have to specify arguments to the "Simulation::init" function. in Simulation.h the arguments (which I would be happy with) are already given. Is empty brackets the way to go then? Code in Simulation.h for class Simulation::init:

namespace LIBSUMO_NAMESPACE {
/**
 * @class Simulation
 * @brief C++ TraCI client API implementation
 */
class Simulation {
public:
#ifdef LIBTRACI
static std::pair<int, std::string> init(int port = 8813, int numRetries =    libsumo::DEFAULT_NUM_RETRIES,
                                        const std::string& host = "localhost", const std::string& label = "default", FILE* const pipe = nullptr);
...
}

It would be great if someone was able to give a short hint. I'm sure my question(s) is/are not that complicated.

Best regards, Lukas

0 Answers0