Downloaded and installed latest RE2. When building simple test code with Xcode 5, build fails.

#include <iostream>
#include <string>
#include <re2/re2.h>
using namespace std;

int main(int argc, const char * argv[])
{
    unsigned long ulValue = 0L;
    string sMultiple;
    string sMatch = "^(\\d+)([KkMm])";
    string sData = "2M";

    if (RE2::FullMatch(sData, sMatch, &ulValue, &sMultiple)) cout << "Match!" << endl;
    return 0;
}
Version info:
Sub-Heading Here

re2-20130802
OS X v10.8.5
g++ --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include- dir=/usr/include/c++/4.2.1 Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix

Errors:
Sub-Heading Here
Undefined symbols for architecture x86_64:
  "re2::RE2::RE2(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
  _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Note:

If I replace the string variables ( sData & sMatch ) with quoted strings, it builds, but has exception when run.

Sub-Heading Here
EXC_BAD_ACCESS
bool RE2::Arg::parse_string(const char* str, int n, void* dest) {
  if (dest == NULL) return true;
  reinterpret_cast<string*>(dest)->assign(str, n);
  return true;
}

Recommended Answers

All 3 Replies

Just a quick question..

Have you installed RE2 correctly? Also, are you linking it correctly when you compile this code? I.e. show what line you use when compiling g++ blah it sounds to me that you're not linking the library properly.

Thanks for looking into this.
RE2 built correctly on my Mac. It could be a link problem but it is not easy to find. You can see the stdlib is set to 'libc++' in the Xcode command line. It is set to '-std=c++11' in the RE2 Makefile and those match.

Xcode command line partial:
-stdlib=libc++ /Users/Christian/Downloads/re2/obj/so/libre2.so

Here is the full command line from Xcode for this target:

Ld /Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Products/Debug/re2tester normal x86_64
    cd /Users/Christian/punk2.0
    setenv MACOSX_DEPLOYMENT_TARGET 10.8
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Products/Debug -L/usr/local/lib -L/Users/Christian/Downloads/re2/obj/so -F/Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Products/Debug -filelist /Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Intermediates/punk2.0.build/Debug/re2tester.build/Objects-normal/x86_64/re2tester.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ /Users/Christian/Downloads/re2/obj/so/libre2.so -Xlinker -dependency_info -Xlinker /Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Intermediates/punk2.0.build/Debug/re2tester.build/Objects-normal/x86_64/re2tester_dependency_info.dat -o /Users/Christian/Library/Developer/Xcode/DerivedData/punk2.0-amlugwfadnrssbdqcornpdaxegpr/Build/Products/Debug/re2tester

Oh. So you are actually compiling through XCode? Do you have the command line tools installed? If so, could you not just attempt to link using GCC (g++) so for example:

Check this link

Might help you. Other than that, I'm stumped since I've never used the library :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.