Getting "Undefined symbols for architecture" linking issue in my C++ module

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By henkdewit


I’m working on my custom C++ module and I’m using a third party library(secp256k1). My code compiles but gives this linking error:

Undefined symbols for architecture x86_64:
      "_secp256k1_context_create", referenced from:
          TestModule::testFunction(String, int) in
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    scons: *** [bin/] Error 1
    scons: building terminated because of errors.

My function:

String TestModule::testFunction(String str, int v) {
     secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);

    return "test";

I’ve used multiple third party libraries and they all give linking problems. Can anyone point me into the right direction? I have downloaded the source code of the library from github and put it into my projects folder. Build it using cmake and included the header file in my C++ module. Syntax is OK, linking goes wrong. I’m on Mac Catalina 10.15.4

Thank you

Does the code have the proper declarations for secp256k1_context_create()? Are the proper headers included in the source files? Is this built with the proper linker commands? I’ve also found this some what related Stack Overflow answer, so it might help.

Ertain | 2021-01-19 18:08