2

I've been given the task of upgrading a VC++ 6.0 solution to VS C++ 2017. Based off of various articles on this site I've gotten the solution to build correctly using VS C++ 2010. But now when I try and upgrade the solution from VS 2010 to VS 2017 I'm getting a link error that I can't seem to figure out. The solution uses the old MS regexpr2 class. I've thought about ripping out the regexpr2 class and putting in something new, but figured I'd try and see if I could make things build first so as not to rock the boat to much.

The error on linking I'm getting is this:

1>regexpr2.obj : error LNK2001: unresolved external symbol "protected: static enum regex::TOKEN const * const regex::perl_syntax_base::s_rgreg" (?s_rgreg@perl_syntax_base@regex@@1QBW4TOKEN@2@B) 1>regexpr2.obj : error LNK2001: unresolved external symbol "protected: static enum regex::TOKEN const * const regex::perl_syntax_base::s_rgescape" (?s_rgescape@perl_syntax_base@regex@@1QBW4TOKEN@2@B)

If I look at the .map file from the VS 2010 successful build I can see this:

0002:00050550 ?s_rgreg@perl_syntax_base@regex@@1QBW4TOKEN@2@B 00000001801ce550 syntax2.obj 0002:00050a20 ?s_rgescape@perl_syntax_base@regex@@1QBW4TOKEN@2@B 00000001801cea20 syntax2.obj

In the Syntax.h file I see this:

class perl_syntax_base
{
protected:
    perl_syntax_base()
    {
    }

    static TOKEN const s_rgreg[ UCHAR_MAX + 1 ];
    static TOKEN const s_rgescape[UCHAR_MAX + 1];

And various usages like this:

 TOKEN tok = look_up( *icur, s_rgreg );

In the Syntax.cpp file I see this:

namespace regex
{

REGEX_SELECTANY TOKEN const perl_syntax_base::s_rgreg[ UCHAR_MAX + 1 ] =
{
/*  0*/    NO_TOKEN,  NO_TOKEN, NO_TOKEN,      NO_TOKEN,    NO_TOKEN,  NO_TOKEN,   NO_TOKEN, NO_TOKEN,
...}

Also from from the Syntax2.h and Syntax.cpp files is this:

Syntax2.h

extern posix_charset_type const g_rgposix_charsets[];

Syntax2.cpp

namespace detail
{

REGEX_SELECTANY extern posix_charset_type const g_rgposix_charsets[] =
{
    { "[:alnum:]",    9 },
    { "[:^alnum:]",  10 },
...}

There is no link error with the g_rgposix_charsets variable, and from the .map file from VS2010 I can see this in the syntax2.obj file

it seems like this solutions were

error LNK2001: unresolved external symbol "private: static class

VS 2012 error LNK2001: unresolved external symbol

But as far as I can tell I am already initializing things appropriately.

Any idea why VS 2017 is complaining about this but VS 2010 successfully builds?

Thanks in advance

Nick
  • 31
  • 3
  • error LNK2001 happen when you are not linking your project with a library that contains the definition of a function you're using from that library.so check that MFC and ATL component installed on your system or not.Go to visual studio installer and check 'individual Component'. If it was installed, check correct version of MFC .lib is use by your project.Read [this](https://learn.microsoft.com/en-us/cpp/porting/overview-of-potential-upgrade-issues-visual-cpp?view=vs-2017) for known upgrade issue in visual c++ – Dimple Patel Jul 16 '20 at 22:41
  • This project doesn't use MFC or ATL. The link was helpful, but didn't resolve the issue. I'm wondering if the issue is a change in the C++ compiler between 2010 and 2017 – Nick Jul 18 '20 at 01:07
  • There are lot of changes in c++ between 2010 and 2017 so it’s difficult to point out particular place of problem.if you don’t mind share your code may be i can help with it – Dimple Patel Jul 18 '20 at 02:19
  • I've tried to share relevant parts of the code in the initial question. Guessing that wasn't enough. I can share a sample project with you if that works? – Nick Jul 20 '20 at 23:08
  • Actually i want to see project configuration,compiler and linker options so it’s good if you share sample project – Dimple Patel Jul 21 '20 at 01:09
  • How should I go about sharing those things with you? – Nick Jul 22 '20 at 20:15
  • upload your project solution on GitHub or anywhere else and provide link in question or comment.or [try to share your contact detail](https://meta.stackexchange.com/questions/57537/how-do-i-contact-other-users). – Dimple Patel Jul 22 '20 at 23:44
  • Ok I will do that and let you know. Thanks – Nick Jul 24 '20 at 18:14
  • Hi, I've uploaded a sample project to GitHub. You can get it here: https://github.com/NickEPalmer/ATLMacrosGreta. if you load the Math.vcxproj project file and build you should get a similar error message to what I'm getting:Subtracter.obj : error LNK2019: unresolved external symbol "protected: bool __thiscall regex::detail::basic_rpattern_base_impl – Nick Jul 28 '20 at 20:35

2 Answers2

1

Problem 1

Subtracter.obj : error LNK2019: unresolved external symbol "protected: bool __thiscall regex::detail::basic_rpattern_base_impl<class std::_String_const_iterator

Cause of this error is,definition of DEFAULT_BLOCK_SIZE(),_ok_to_recurse() and other functions are available in regexpr2.cpp so you have two choice either compile whole that Greta library stuff into separate project and give reference of resultant .lib into this project . OR include regexpr2.cpp and syntax2.cpp into your 'Source Files' folder of .vcxproj as a result .obj file of that two files will be generated and link successfully.

Problem 2 After solving problem 1, main problem is still exist

regexpr2.obj : error LNK2001: unresolved external symbol "protected: static enum regex::TOKEN const * const regex::perl_syntax_base::s_rgreg" (?s_rgreg@perl_syntax_base@regex@@1QBW4TOKEN@2@B) 1>regexpr2.obj : error LNK2001: unresolved external symbol "protected: static enum regex::TOKEN const * const regex::perl_syntax_base::s_rgescape" (?s_rgescape@perl_syntax_base@regex@@1QBW4TOKEN@2@B)

This problem is because of REGEX_SELECTANY

# define REGEX_SELECTANY        __declspec(selectany)

I am not sure how to modify this code because Greta library is very time consuming to understand and it was very old code from Microsoft.there are many syntactical and other changes as per the latest visual studio changes in VC++ so may be it will be possible that after solving this issues your code compile and link successfully but there will be problem in execution but anyway let's move to solution,

this link error is solve if we remove REGEX_SELECTANY from below lines in "syntax2.cpp"

REGEX_SELECTANY TOKEN const perl_syntax_base::s_rgescape[ UCHAR_MAX + 1 ] =
REGEX_SELECTANY TOKEN const perl_syntax_base::s_rgreg[UCHAR_MAX + 1] =

if you want to learn more about __declspec(selectany) refer this.

Dimple Patel
  • 718
  • 1
  • 4
  • 14
  • Thanks for the response. After a lot of head banging I finally figured out how to resolve the link issue. – Nick Jul 29 '20 at 22:28
  • Hi @Nick,if this answer really helps you to resolve your question please [accept and upvote](https://stackoverflow.com/help/someone-answers) so it will help someone else as well – Dimple Patel Aug 06 '20 at 23:24
0

After some head banging, I figured out how to resolve my issue with the missing symbols in the link process

In the syntax.h file there are two definitions:

static TOKEN const s_rgreg[ UCHAR_MAX + 1 ];
static TOKEN const s_rgescape[UCHAR_MAX + 1];

The original declarations of these were in the syntax.cpp file:

REGEX_SELECTANY TOKEN const perl_syntax_base::s_rgreg[UCHAR_MAX + 1] =
{...}

REGEX_SELECTANY TOKEN const perl_syntax_base::s_rgescape[UCHAR_MAX + 1] =
{..}

I commented those out and moved these declarations to the regexpr2.cpp file.

After making this change I was able to do a full build with no link errors and confirm that things worked correctly.

Thanks Dimple for your help.

Nick
  • 31
  • 3