前提:我的代码文件是cpp。
原始输入:
gcc modbus_TCP_test.cpp -L/home/xxx/libmodbus/install/lib -lmodbus
报错信息:
/tmp/ccy4FgrD.o: In function `__static_initialization_and_destruction_0(int, int)':
modbus_TCP_test.cpp:(.text+0x190): undefined reference to `std::ios_base::Init::Init()'
modbus_TCP_test.cpp:(.text+0x1a4): undefined reference to `std::ios_base::Init::~Init()'
modbus_TCP_test.cpp:(.text+0x1a8): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
正确输入:
g++ modbus_TCP_test.cpp -L/home/zbr/zbr/libmodbus/install/lib -lmodbus
gcc 改成 g++就不报错了。
参考资料:
https://stackoverflow.com/questions/10906275/undefined-reference-to-stdios-baseinitinit
Linux环境C++编译报错:undefined reference to `std::ios_base::Init::Init()
此方法只是恰好解决了我的问题,具体原因我也不懂,如果有存在什么错误,或恰好您知道原因,欢迎在评论区留言,感激不尽!!!