Unable to export class in shared library

  • Thread starter Thread starter DP320
  • Start date Start date
D

DP320

Guest
I am trying to use the Google RE2 regex parser in my project. Due to constraints that are outside of my control, the project only supports VS 2010. RE2 requires VS 2015. So I built a simple shared library to facilitate the only parts of RE2 that I need (match function). Attached is my code. I generate a re2.lib, but when I try to include that in my VS 2010 project, it does not see the required functions declared in the Google RE2 project referenced in the shared project CPP (below). I used dumpbin utility and no function are exported. How do I get my shared library (basically a wrapper) to also include all of the shared library (Google RE2) that it is referencing during compile. Here is my function:

Shared Library Header:


#pragma once

class RE2;
using namespace std;

class __declspec(dllexport) BasicRegex {
public:
BasicRegex(const char* str);
~BasicRegex();


bool fullMatch(const char* str);

private:
RE2* gre2;
};


Shared Library CPP:

// RE2_Interface.cpp : Defines the functions for the static library.
//

#include "pch.h"
#include "framework.h"
#include "re2/re2.h"
#include "re2lib.h"


BasicRegex::BasicRegex(const char* str) {
this->gre2 = new RE2(str);
}

BasicRegex::~BasicRegex() {
delete gre2;
}

bool BasicRegex::fullMatch(const char* str) {
re2::StringPiece matchstr = re2::StringPiece(str);
return gre2->Match(str, 0, matchstr.length(), re2::RE2::Anchor::ANCHOR_BOTH, NULL, 0);
}



Example Test .cpp

#include <iostream>
#include "re2lib.h"

using namespace std;

int main()
{
BasicRegex regex = BasicRegex("ruby:1234");
bool found = regex.fullMatch("(.*):(\\d+)");

cout << "Found: " << found << endl;
}

Shared library project was setup as a shared library project in VS 2019. Test example project setup as a Console application in VS 2019. Shared library compiled without warning. Example project produced the following errors:

1>RE2_LIB.lib(re2lib.obj) : error LNK2001: unresolved external symbol "public: __cdecl re2::RE2::RE2(char const *)" (??0RE2@re2@@QEAA@PEBD@Z)
1>RE2_LIB.lib(re2lib.obj) : error LNK2001: unresolved external symbol "public: __cdecl re2::RE2::~RE2(void)" (??1RE2@re2@@QEAA@XZ)
1>RE2_LIB.lib(re2lib.obj) : error LNK2001: unresolved external symbol "public: bool __cdecl re2::RE2::Match(class re2::StringPiece const &,unsigned __int64,unsigned __int64,enum re2::RE2::Anchor,class re2::StringPiece *,int)const " (?Match@RE2@re2@@QEBA_NAEBVStringPiece@2@_K1W4Anchor@12@PEAV32@H@Z)
1>C:\Users\ack\Documents\Visual Studio 2019\Projects\Scratch4\x64\Release\RE2.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "Scratch4.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Continue reading...
 
Back
Top