I have just created a new project in Xcode 8.3.3 with Swift for iOS and I tried importing the external library SwiftLibModbus
I have ported the library to use Swift 3 (meaning, I fixed all the errors).
This library is using another library named libmodbus
that is written in C
and I am getting an Undefined symbols for architecture x86_64
error when this library is imported.
Here is the full error:
Undefined symbols for architecture x86_64:
"_modbus_free", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbusD in SwiftLibModbus.o
"_modbus_strerror", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbusP33_56F751289226F31D555D5DEEC0F0514F12buildNSErrorfT5errnoVs5Int32_CSo7NSError in SwiftLibModbus.o
"_modbus_write_registers", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus23writeRegistersFromAndOnFT7addressVs5Int3211numberArrayCSo7NSArray7successFT_T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_read_input_registers", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus22readInputRegistersFromFT12startAddressVs5Int325countS1_7successFGSaPs9AnyObject__T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_write_register", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus13writeRegisterFT7addressVs5Int325valueS1_7successFT_T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_write_bit", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus8writeBitFT7addressVs5Int326statusSb7successFT_T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_new_tcp", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus8setupTCPfT9ipAddressCSo8NSString4portVs5Int326deviceS2__Sb in SwiftLibModbus.o
"_modbus_set_error_recovery", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus8setupTCPfT9ipAddressCSo8NSString4portVs5Int326deviceS2__Sb in SwiftLibModbus.o
"_modbus_close", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus10disconnectfT_T_ in SwiftLibModbus.o
"_modbus_connect", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus16connectWithErrorfCSo7NSErrorSb in SwiftLibModbus.o
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus7connectFT7successFT_T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_read_registers", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus17readRegistersFromFT12startAddressVs5Int325countS1_7successFGSaPs9AnyObject__T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_read_input_bits", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus17readInputBitsFromFT12startAddressVs5Int325countS1_7successFGSaPs9AnyObject__T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_read_bits", referenced from:
__TFFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus12readBitsFromFT12startAddressVs5Int325countS1_7successFGSaPs9AnyObject__T_7failureFCSo7NSErrorT__T_U_FT_T_ in SwiftLibModbus.o
"_modbus_set_slave", referenced from:
__TFC23SomeProject_Wi_Fi_Connect14SwiftLibModbus8setupTCPfT9ipAddressCSo8NSString4portVs5Int326deviceS2__Sb in SwiftLibModbus.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there any way around this? This is actually the only library I have found available for Modbus.
Thanks :)
Hmmm... Did you drag the files inside a folder using "Copy items if needed" and "Create folder references" marked?
If so, Xcode might not understand it needs to compile the files for the right architecture inside that folder. Just drag the bunch of files directly to Xcode and it should be fine.