libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

Simple code compilation problem - linker error LNK2019 - only with RTU

Open aLAN-LDZ opened this issue 2 years ago • 1 comments

Hello, when I try to compile my code based on modbus-rtu I get an error with every function from your library

example:

`#include <modbus.h>

int main() {

modbus_t* ctx;
ctx = modbus_new_rtu("\\\\.\\COM5", 38400, 'N', 8, 1);

}`

error:

LNK2019 unresolved external symbol _modbus_new_rtu referenced in function _main.

In case of using functions from the TCP library there is no this problem, unfortunately my device does not support TCP :( Please help if possible

  • libmodbus version: 3.1.7
  • Windows / Visual Studio 2019
  • CPU architecture, 64 bit

aLAN-LDZ avatar Jul 07 '22 05:07 aLAN-LDZ

I can't help you with Visual Studio issue, may be someone will be able...

stephane avatar Jul 29 '22 10:07 stephane

FYI: is your project add the lib path?

SnorlaxGengar avatar Aug 12 '22 07:08 SnorlaxGengar

I fixed this problem using a changed library by one of users

aLAN-LDZ avatar Aug 12 '22 07:08 aLAN-LDZ

This is what helped me when building the lib (mscv 2019, x64) so I'm just gonna put it here. It's from this post by Matthew Wachter.

Ok, got it to compile in x64 without too much difficulty. Just set your platform to x64 and make sure your set these settings in the project property pages:

General / Project Defaults / Configuration Type = Dynamic Library (.dll) Linker / Input / Additional Dependencies = ws2_32.lib

mthongkerd avatar Aug 16 '22 15:08 mthongkerd

OK, notes added to next version of the documentation.

stephane avatar Aug 17 '22 13:08 stephane