简体   繁体   中英

Linking Error - C++ Clang MacOs

I have two projects, both built with clang++ and Xcode on MacOS.

I have a library with a header defined as follows.... (serialization.h)

#pragma once

#include <visionApp/cv/matchers/visual_database.h>

namespace visionApp {
    void serializeDB(visionApp::VisualDb visualDB, std::string fileName);
    visionApp::VisualDb* deserializeDB(std::string fileName);
}

The cpp file is as follows.... (serialization.cpp)

#include "serialization.h"

namespace visionApp {

        void serializeDB(visionApp::VisualDb visualDB, std::string fileName)
        {
        }

        visionApp::VisualDb* deserializeDB(std::string fileName)
        {
           return new visualDB();
        }
}

The method is then called in another class.....

void saveRecogniser(std::string fileName)
{
    serializeDB(currentVisualDB.get(), fileName);
}

void loadRecogniser(std::string fileName)
{
    mVisualDatabase.reset(deserializeDB(fileName));
}

Note: currentVisualDB is a shared pointer to .get() returns a pointer.

This all builds fine. Which is great...... and make libvisionApp.a

But when i build a dependent application that can only see the headers i get the following error....

Undefined symbols for architecture x86_64:
  "visionApp::serializeRecognizer(visionApp::VisualDb*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      visionApp::Recogniser::saveRecogniser(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in libvisionApp.a(planar_recogniser.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Now, this linking error suggests that clang is not able to link the serialize method, but it has no problems with the deserialize method. Removing the serialize method, and leaving only the deserialize builds correctly.

I do not understand this issue, and am unsure how to proceed. Can someone educate me as what to do in a situation like this?

Any advice on how to tackle this issue?

Note: Lipo output for the library in question.

Hal:Release daniel$ lipo -info libvisionDB.a
input file libvisionDB.a is not a fat file
Non-fat file: libvisionDB.a is architecture: x86_64

You have declared serializeDB to get first parameter by value.

void serializeDB(visionApp::VisualDb visualDB, std::string fileName);

When you call the function, you use a pointer as first parameter:

void saveRecogniser(std::string fileName)
{
    serializeDB(currentVisualDB.get(), fileName); // You said that currentVisualDB is a std::shared_ptr
}

I don't know why your build gets to linking stage, it shouldn't. Maybe you have more than one place where you declare serializeDB ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM