Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed on MacOS #22

Open
laurent-bohr opened this issue Mar 6, 2025 · 1 comment
Open

Build failed on MacOS #22

laurent-bohr opened this issue Mar 6, 2025 · 1 comment

Comments

@laurent-bohr
Copy link

Hi,

Using the lastest release v1.0.1, build of the crate failed, using crates.io or git version :

  cargo:warning=In file included from libmodbus/src/modbus-rtu.c:17:
  cargo:warning=libmodbus/src/modbus-private.h:111:8: error: expected parameter declarator
  cargo:warning=  111 | size_t strlcpy(char *dest, const char *src, size_t dest_size);
  cargo:warning=      |        ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:47: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                                                             ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:41:62: note: expanded from macro '__darwin_obsz'
  cargo:warning=   41 | #define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
  cargo:warning=      |                                                              ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:32:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
  cargo:warning=   32 | #    define _USE_FORTIFY_LEVEL 2
  cargo:warning=      |                                ^
  cargo:warning=In file included from libmodbus/src/modbus-rtu.c:17:
  cargo:warning=libmodbus/src/modbus-private.h:111:8: error: expected ')'
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:47: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                                                             ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:41:62: note: expanded from macro '__darwin_obsz'
  cargo:warning=   41 | #define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
  cargo:warning=      |                                                              ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:32:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
  cargo:warning=   32 | #    define _USE_FORTIFY_LEVEL 2
  cargo:warning=      |                                ^
  cargo:warning=libmodbus/src/modbus-private.h:111:8: note: to match this '('
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:47: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                                                             ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:41:53: note: expanded from macro '__darwin_obsz'
  cargo:warning=   41 | #define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
  cargo:warning=      |                                                     ^
  cargo:warning=In file included from libmodbus/src/modbus-rtu.c:17:
  cargo:warning=libmodbus/src/modbus-private.h:111:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
  cargo:warning=  111 | size_t strlcpy(char *dest, const char *src, size_t dest_size);
  cargo:warning=      |        ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:47: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                                                             ^
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_common.h:41:31: note: expanded from macro '__darwin_obsz'
  cargo:warning=   41 | #define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
  cargo:warning=      |                               ^
  cargo:warning=In file included from libmodbus/src/modbus-rtu.c:17:
  cargo:warning=libmodbus/src/modbus-private.h:111:8: error: conflicting types for '__builtin___strlcpy_chk'
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:3: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                 ^
  cargo:warning=libmodbus/src/modbus-private.h:111:8: note: '__builtin___strlcpy_chk' is a builtin with type 'unsigned long (char *, const char *, unsigned long, unsigned long)'
  cargo:warning=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:112:3: note: expanded from macro 'strlcpy'
  cargo:warning=  112 |                 __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
  cargo:warning=      |                 ^
  cargo:warning=4 errors generated.

  --- stderr

Any ideas how to solve this ?

@laurent-bohr
Copy link
Author

The error is due to the name strlcpy already defined in the MacOS libs, doing a conflict with project sources.

Found a workaound :

Add this env var before running the cargo commands: CFLAGS="-D_FORTIFY_SOURCE=0"

For example: CFLAGS="-D_FORTIFY_SOURCE=0" cargo build

It will be fine to add a conditional config for the build of this crate by I'm new on Rust and I don't know how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant