googletest
googletest copied to clipboard
Posix regex not found. Other regex produces compilation errors
This is for googletest release 1.11.0 Compiling on MacOs Catalina Trying to compile this sample code:
#include "gtest/gtest.h"
// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);
}
Initially produced these errors:
/Users/jsaremi/install_folder/include/gtest/internal/gtest-port.h:929:3: error: unknown type name 'regex_t'
regex_t full_regex_; // For FullMatch().
^
/Users/jsaremi/install_folder/include/gtest/internal/gtest-port.h:930:3: error: unknown type name 'regex_t'
regex_t partial_regex_; // For PartialMatch().
^
I tried disabling the POSIX option by including these lines prior to "gtest.h". That did not work:
#define GTEST_USES_SIMPLE_RE 1
#define GTEST_USES_POSIX_RE 0
then I tried the following:
#define GTEST_USES_PCRE 1
#define GTEST_USES_SIMPLE_RE 1
#include "gtest/gtest.h"
This time I got the following errors:
In file included from /Users/jsaremi/src/install_folder/main/src/framework/tests/GTestSample.cpp:18:
In file included from /Users/jsaremi/install_folder/include/gtest/gtest.h:64:
In file included from /Users/jsaremi/install_folder/include/gtest/gtest-death-test.h:41:
In file included from /Users/jsaremi/install_folder/include/gtest/internal/gtest-death-test-internal.h:39:
/Users/jsaremi/install_folder/include/gtest/gtest-matchers.h:798:29: error: unknown type name 'RE'
MatchesRegexMatcher(const RE* regex, bool full_match)
^
/Users/jsaremi/install_folder/include/gtest/gtest-matchers.h:842:31: error: unknown type name 'RE'
const std::shared_ptr<const RE> regex_;
^
/Users/jsaremi/install_folder/include/gtest/gtest-matchers.h:826:26: error: use of undeclared identifier 'RE'
return full_match_ ? RE::FullMatch(s2, *regex_)
^
/Users/jsaremi/install_folder/include/gtest/gtest-matchers.h:827:26: error: use of undeclared identifier 'RE'
: RE::PartialMatch(s2, *regex_);
^
What is the rightway of ensuring that Regex code compiles?
Thanks
Please provide the full details (commands etc) on how you are building and installing GoogleTest.
I have built this using CMake with the following flags:
"-DCMAKE_PREFIX_PATH=" + runprefix,
"-DCMAKE_INSTALL_PREFIX=" + runprefix,
"-DCMAKE_INSTALL_LIBDIR=lib",
"-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE",
"-DBUILD_GMOCK=ON",
"-DINSTALL_GTEST=OFF",
And since "make install" did not seem to be available I used the following equivalent to install it:
cmd_install=[
["COPY"] + ["lib/libgtest.a", os.path.join(runprefix, "lib")],
["COPY"] + ["lib/libgmock.a", os.path.join(runprefix, "lib")],
["COPY"] + ["lib/libgtest_main.a", os.path.join(runprefix, "lib")],
["COPY"] + ["lib/libgmock_main.a", os.path.join(runprefix, "lib")],
["CD", "googletest/include"],
["COPYALL"] + [os.path.join(runprefix, "include")],
["CD", "googlemock/include"],
["COPYALL"] + [os.path.join(runprefix, "include")],
],
I'm also compiling on Catalina and I couldn't reproduce the issue anymore.