This question already has an answer here:
In a process to clean my code, I converted two parameters that were previously of string type to enums. However, I now get a linker error that says that my class constructor(where I changed from strings to enums) is undefined. In my .h file I have the declaration of the enums and the constructor:
enum flow_control{no_flow_control, software, hardware};
enum parity{no_parity, odd, even};
Serial(std::string port_name, boost::asio::io_service* io, std::size_t baud_rate, flow_control serial_flow_control = no_flow_control, parity serial_parity = no_parity, float stop_bits = 1.0);
And then I instantiate it with the same types and amount of parameters
Serial::Serial(std::string port_name, boost::asio::io_service* io, std::size_t baud_rate, flow_control serial_flow_control, parity serial_parity, float stop_bits):port_name_(){
this->set_port(new boost::asio::serial_port(*io, port_name));
typedef std::allocator<char> Allocator;
Allocator* alloc = new Allocator();
b_ = new boost::asio::streambuf(TOTAL_BYTES_IN_STREAMBUF, *alloc);
this->configure_baud_rate(baud_rate);
this->configure_parity(serial_parity);
this->configure_flow_control(serial_flow_control);
//Configure stop_bits
if(stop_bits == 1.0){
port_->set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::one));
}
else if(stop_bits == 1.5){
port_->set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::onepointfive));
}
else{
port_->set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::two));
}
openAndWaitOnPort(port_name);
}
The exact error I get is
Undefined symbols for architecture x86_64:
"Serial::Serial(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::asio::io_service*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, parity, float)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
The parity enum parameter and the std::size_t parameter appear to be getting recognized correctly, as does the string parameter and float parameter. However, the error does not look as if the compiler recognizes the flow_control enum. Any ideas as to why this might be?
EDIT: This is a different question from the duplicate provided. My question is in the scope of the parameters of a constructor with default value enums, not within the scope of linker errors other than undefined symbol errors. I have removed the linker tag.
Aucun commentaire:
Enregistrer un commentaire