stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

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

Closed aLAN-LDZ closed 2 years ago

aLAN-LDZ commented 2 years ago

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

example:

`#include

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

stephane commented 2 years ago

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

SnorlaxGengar commented 2 years ago

FYI: is your project add the lib path?

aLAN-LDZ commented 2 years ago

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

mthongkerd commented 2 years ago

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

stephane commented 2 years ago

OK, notes added to next version of the documentation.