编译时出现OSX错误:"架构x86_64"的未定义符号

时间:2015-03-29 04:13:26

标签: c++

代码:

bloomierFilter.h

#ifndef __BloomierFilter_H_
#define __BloomierFilter_H_

#include <map>
#include <vector>
#include <iostream>
#include <cstddef>
#include <cstring>
#include "core/util.h"
#include "core/utilEncode.h"
#include "core/bloomierHasher.h"
#include "core/orderAndMatchFinder.h"

namespace bloomier {

class BloomierFilter {
    int hashSeed;
    std::map<std::string, int>* keyMap;
    OrderAndMatchFinder* oam = NULL;
    OrderAndMatch* om = NULL;
    BloomierHasher* h = NULL;

    int m;
    int k;
    int q;
    int byteSize;

    unsigned char *table = NULL;
    // not size optimal, only for testing purposes
    int *valueTable = NULL;
public:
    BloomierFilter(int hashSeed, std::map<std::string, int>* keyMap, int m, int k, int q);
    ~BloomierFilter();
    void create(std::map<std::string, int>* keyMap, OrderAndMatchFinder* oam);
    bool get(std::string key, int& value);
    bool set(std::string key, int value);
};

}
#endif //__BloomierFilter_H_

的main.cpp

class bloomBloomier
{

public:

    void instantiate(int n, float p){

        bloom_filter blmFilter = instBloom(n,p);

        initSignatureDatabase(blmFilter);

        std::map<std::string, int>* keyMap =  blmFilter.getKVs();

/*        long int j = keyMap->size();
        int m = (-j * std::log(0.01) / std::pow(log(2),2));
        int k = 0.7 * (m/n);
        int q = log(k/0.05);*/

        int hash = 0; int m = 10; int k = 5; int q = 24;
        map<string, int> mp; mp["abc"] = 10; mp["def"] = 20; mp["abd"] = 30;
        vector<string> keys = {"abc", "def", "abd"};
        auto bf = bloomier::BloomierFilter(hash, &mp, m, k, q);



        //TODO: allow db to be symbolic path


    }

    //creates bloom filter
    bloom_filter instBloom(int n, float p){
        bloom_parameters parameters;

        // expected element count
        parameters.projected_element_count = n;

        // false probability allowance
        parameters.false_positive_probability = p; // 1 in 10000

        parameters.compute_optimal_parameters();

        bloom_filter filter(parameters);

        return filter;
    }


    //loads bloom filter
    void initSignatureDatabase(bloom_filter filter){
        std::ifstream keys;

        keys.open("/PATH/TO/DB.txt");

        if (keys.is_open() == false) {
            std::cout << "not open";
        }

        std::string line;
        while( getline(keys, line) ) {
            int start = line.find(":");
            std::string substring = line.substr( start + 1, (start + 33) - (start) -1 );
            filter.insert(substring);

        }

    }
};

int main()
{
    std::vector<std::string> knownPatterns;

    bloomBloomier mechanism;
    mechanism.instantiate(3600000,0.01);

    return 0;
}

我在'auto bf = bloomier :: BloomierFilter ...'

之后收到此错误
Linking CXX executable BloomBloomier

Undefined symbols for architecture x86_64:

  "bloomier::BloomierFilter::BloomierFilter(int, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> > >*, int, int, int)", referenced from:

      bloomBloomier::instantiate(int, float) in main.cpp.o
  "bloomier::BloomierFilter::~BloomierFilter()", referenced from:

      bloomBloomier::instantiate(int, float) in main.cpp.o
ld: symbol(s) not found for architecture x86_64

导致错误的代码块使用相同的CMakeLists条件从库测试套件中完美地运行(c + p'ed)。这是项目的CMakeLists.txt文件(我是CMake的新手,所以这可能导致错误):

cmake_minimum_required(VERSION 3.1)
project(BloomBloomier)

# cmake -DCMAKE_BUILD_TYPE:STRING=Debug ../src
# http://www.cmake.org/Wiki/CMake_Useful_Variables#Compilers_and_Tools
set(CMAKE_CXX_FLAGS_DEBUG, ON)
set(CMAKE_CXX_COMPILER "/usr/bin/c++")
#set(CMAKE_CXX_COMPILER "/usr/bin/llvm-g++")
# http://stackoverflow.com/questions/5334095/cmake-multiarchitecture-compilation
set(CMAKE_CXX_FLAGS "-std=c++11 -m64")
# cmake -DCMAKE_OSX_ARCHITECTURES=x86_64


set(SOURCE_FILES main.cpp)

set(bloomier_srcs
    # bloomier filter code
    libs/bloomierFilter/BloomierFilter.cpp
    libs/bloomierFilter/core/util.cpp
    libs/bloomierFilter/core/utilEncode.cpp
    libs/bloomierFilter/core/hash.cpp
    libs/bloomierFilter/core/bloomierHasher.cpp
    libs/bloomierFilter/core/singletonFindingTweaker.cpp
    libs/bloomierFilter/core/orderAndMatchFinder.cpp
    )

add_library(bl ${bloomier_srcs})
include_directories(/usr/local/include)
include_directories(.)
include_directories(./libs)
include_directories(./libs/bloom)
include_directories(./libs/bloomierFilter)
include_directories(./libs/bloomierFilter/core)
link_directories(/usr/local/lib)

add_executable(BloomBloomier ${SOURCE_FILES})

TARGET_LINK_LIBRARIES(BloomBloomier ${bl})

如果有帮助,我正在运行Mavericks 10.10 64位。谢谢你的帮助。

更新: 我搜索了一些使用libstdc ++推荐的解决方案。我使用它作为编译器选项并更改了源代码以使用它(仅取出了c ++ 11的东西),但是抛出了完全相同的错误。

0 个答案:

没有答案