"undefined reference" When linking to a C library

Hi, I’m trying to link to sciter C library, however, I keep encountering the issue of:

/home/ubuntu/projects/sciter-tests/src/sciter.cr:12: undefined reference to `SciterCreateWindow’

Code can be found here: GitHub - WhoAteDaCake/sciter-tests
crystal build src/main.cr command

The similar code, but in C compiles without problems: GitHub - WhoAteDaCake/sciter-repro

Am I doing the bindings incorrectly?

  1. Make sure the C function is actually marked as extern so that it’s listed in the resulting C library (nm -D path/to/library.so on Linux, or otool -L path/to/library.dylib on macOS).
  2. It looks like that function is omitted if WINDOWLESS is defined. Might double check how the library was configured/compiled.
  3. As others apparently already pointed out in Discord, make sure the function is in fact a C function, and not a C++ function. If you are compiling/linking to a C++ library, make sure to wrap any C function declarations inside a extern "C" { ... } block.

Thanks for the help. I managed to build it properly, by first building a C file, where I re-defined all functions, then use that library file as the main entry. You can see it here GitHub - WhoAteDaCake/sciter-tests