Why am I getting error: Undefined symbols for architecture x86_64?

  amqp, c++, nats.io, server

Tools: MacOS, C++, Brew, nats.c

Hi, there. I’m trying to connect the program with NATS. The library that I used is https://github.com/nats-io/nats.c

Small piece of code:

    #include <iostream>
    #include "nats/nats.h"
    
    using std::cout;
    using std::endl;
    using std::string;
    
    int main() {
        cout << "[App] Started" << endl;
        natsConnection      *conn  = NULL;
        natsConnection_ConnectTo(&conn, NATS_DEFAULT_URL);
    }

CMake file:

    cmake_minimum_required(VERSION 3.17)  
    project(broker)  
    
    set(CMAKE_CXX_STANDARD 20)  
    
    set(CNATS_INCLUDE "/usr/local/Cellar/cnats/2.5.1/include")  
    include_directories(${CNATS_INCLUDE})  
    
    set(THREADS_PREFER_PTHREAD_FLAG ON)  
    find_package(Threads REQUIRED)  
    
    add_executable(broker main.cpp)  

But when I trying to run this:

    [ 50%] Linking CXX executable broker  
    Undefined symbols for architecture x86_64:  
      "_natsConnection_ConnectTo", referenced from:  
          _main in main.cpp.o  
    ld: symbol(s) not found for architecture x86_64  
    clang: error: linker command failed with exit code 1 (use -v to see invocation)  
    make[3]: *** [broker] Error 1  
    make[2]: *** [CMakeFiles/broker.dir/all] Error 2  
    make[1]: *** [CMakeFiles/broker.dir/rule] Error 2  
    make: *** [broker] Error 2

Source: Windows Questions C++

LEAVE A COMMENT