userM7Lh5621CD0P
userM7Lh5621CD0P

Reputation: 11

Compiler Error : Undefined symbols for architecture x86_64

Compiler failed with error Undefined symbols for architecture x86_64

macOS 10.15.6 Catalina

compiler

g++-11 --version

g++-11 (Homebrew GCC 11.2.0_3) 11.2.0

error :

Undefined symbols for architecture x86_64:
  "__ZN4ssdb6Client7connectEPKci", referenced from:
      _main in cciJLzzz.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

.cpp

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include "SSDB_client.h"

int main(int argc, char **argv){
    const char *ip = (argc >= 2)? argv[1] : "127.0.0.1";
    int port = (argc >= 3)? atoi(argv[2]) : 8888;
    
    ssdb::Client *client = ssdb::Client::connect(ip, port);

    if(client == NULL){
        printf("fail to connect to server!\n");
    }else{
        printf("ssdb client\n");
    }

    delete client;
    return 0;
}

is there a notation issue here ?

namespace ssdb, class client ..

if I replace this line :

ssdb::Client *client = ssdb::Client::connect(ip, port);

with :

ssdb::Client *client = 0;

the compiler works and I don't get this error ..

the above code is from ssdb docs :

ssdb docs

ssdb docs C++ client

I would like to connect to the ssdb server ..

EDIT :

For command requests

g++ -o hello-ssdb hello-ssdb.cpp libssdb-client.a

..in libssdb-client.a(SSDB_impl.o)
..in libssdb-client.a(link.o)

ld: symbol(s) not found for architecture x86_64




g++ -o hello-ssdb.cpp hello-ssdb libssdb-client.a

ld: can't link with a main executable file

Regarding libssdb-client.a

ar t libssdb-client.a

__.SYMDEF
SSDB_impl.o
bytes.o
link.o
link_addr.o

..

using ssdb for long time but with php client. fine in most cases, but there is something I have to iterate many many times .. and with C/C++ I should be able to save a lot of time ..

..

Workaround :

package main

import (
    "fmt"
    "os"
    "ssdb"
)

func main() {

    fmt.Println("We will use Golang .. \n")

    ip := "127.0.0.1"
    port := 8888
    db, err := ssdb.Connect(ip, port)
    if err != nil {
        os.Exit(1)
    }

    defer db.Close()
    var val interface{}

    keys := []string{}
    keys = append(keys, "c");
    keys = append(keys, "d");
    val, err = db.Do("multi_get", "a", "b", keys);
    fmt.Printf("%s\n", val);

    db.Set("a", "xxx")
    val, err = db.Get("a")
    fmt.Printf("%s\n", val)

    fmt.Printf("----\n");
    
    return
}

Upvotes: 1

Views: 382

Answers (1)

Bill Lynch
Bill Lynch

Reputation: 81916

Note that in the documentation for ssdb, they include a libssdb.a that you need to link:

g++ -o hello-ssdb hello-ssdb.cpp libssdb.a

This would have the implementation of all the code for ssdb and is why you are seeing the problem you are seeeing.

Upvotes: 1

Related Questions