{"id":684,"date":"2022-08-30T15:05:27","date_gmt":"2022-08-30T15:05:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-googletest-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:27","modified_gmt":"2022-08-30T15:05:27","slug":"problem-about-googletest-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-googletest-collection-of-common-programming-errors\/","title":{"rendered":"problem about googletest-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/00b470b366fab2b350ae7225373faa45?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ngnash117<br \/>\nc++ testing build linker googletest<br \/>\nI am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating ld: warning: in \/usr\/local\/lib\/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)I have tried to make the issue as simple as possible:I have a main function cmtest.cc#include \/** Main entry point *\/ int main(int argc, char**argv, char**envArg) {testing::InitGoogleTest(&amp;argc, argv);return(RUN_ALL_TESTS()); }really basic test code CrazyTest.cc#include TEST(CrazyTest, one) {EXPECT_EQ(2, 2); }I use the following commands to build gtest and my test code.g++ -o CrazyTest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I\/opt\/gtest-1.6.0\/include CrazyTest.ccg++ -o cmtest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I\/opt\/gtest-1.6.0\/include cmtest.ccg<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/95e7439332def9c8b26802e40f6a5993?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndmonopoly<br \/>\nc++ googletest<br \/>\nI&#8217;ve been trying to get used to c++ with cmake and gtest (google test).I&#8217;m trying to understand why this setup yields the error Undefined symbols for architecture x86_64: &#8220;Project1::foo(int&amp;)&#8221;, referenced from:Project1Test_MethodBarDoesAbc_Test::TestBody() in test_project1.cpp.old: symbol(s) not found for architecture x86_64when I run &#8220;make&#8221;. When I implement methods in the .h file, things work fine; but when I only declare methods in the .h file and then implement it in the associated .cpp file, this error occurs.My test file: test_project1.cpp#include #include &#8220;gtest\/gtest.h&#8221;#include &#8220;project1.h&#8221;\/\/ tests outside of the class TEST(IndependentMethod, ResetsToZero2) {int i = 0;independentMethod(i);EXPECT_EQ(0, i); } \/\/&#8230;\/\/ The fixture for testing the class class Project1Test : public ::testing::Test { protected<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/eab3a3d67dbdcc0eefc26252702cb4c1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAnton<br \/>\nwindows qt mingw googletest<br \/>\nI have a Qt project and i wanted to use google tests framework GoogleTestFramework in order to do google test. The framework compiled fine on Linux.I have managed to compile the libraries on windows, using tips provided in the following link: Installing Gtest without pthreadsThe following advice do not let me compile the libraries, because of errors due to pthreads: Sackoverflow compiling with MSYSI<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b12ab7a72d6d5062ccfd3a18f950f57d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBaz<br \/>\nc++ googletest<br \/>\nWhy does a test fixture have a SetUp method in Google Test? Isn&#8217;t the Cons<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c591adda9130a2b3b3a30ed5201d59f8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDave Mateer<br \/>\nqt googletest<br \/>\nI have a simple test file, TestMe.cpp:#include TEST(MyTest, SomeTest) {EXPECT_EQ(1, 1); }int main(int argc, char **argv) {::testing::InitGoogleTest(&amp;argc, argv);return RUN_ALL_TESTS(); }I have Google Test built as a static library. (I can provide the makefile if it&#8217;s relevant.)I can compile TestMe.cpp from a command-line with no problem:g++ TestMe.cpp -IC:\\gtest-1.5.0\\gtest-1.5.0\\include -L..\/gtest\/staticlib -lgte<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/db869d4e8c636d15bd18678f6ced444b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nShafik Yaghmour<br \/>\nlinux gcc googletest<br \/>\nWhen I compile gtest samples on Redhat OS(gcc version is 3.2.2),it throw the error as below,howere it compile on Ubuntu it&#8217;s OK.Pleae help me. Error or Warning:..\/include\/gtest\/internal\/gtest-internal.h: In instantiation of `testing::internal::ImplicitlyConvertiblemT,mT);message_data-&gt;rUID[0] = &#8216;\\0&#8217;;mes<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/2KUY6.jpg?s=32&amp;g=1\" \/><br \/>\nB\u0408\u043e\u0432\u0438\u045b<br \/>\nlinker-error googletest<br \/>\nI was trying to set up GTest environment on my Ubuntu machine. but while making the GTest to get the library, i get the following error&#8230;som@som-VPCEH25EN:~\/Workspace\/CPP\/gtest-1.6.0\/make$ make g++ -I..\/include -g -Wall -Wextra -lpthread sample1.o sample1_unittest.o gtest_main.a -o sample1_unittest gtest_main.a(gtest-all.o): In function `~ThreadLocal&#8217;: \/home\/som\/Workspace\/CPP\/gtest-1.6.0\/make\/..\/include\/gtest\/internal\/gtest-port.h:1336: undefined reference to `pthread_getspecific&#8217; \/home\/som\/Workspace\/CPP\/gtest-1.6.0\/make\/..\/include\/gtest\/internal\/gtest-port.h:1340: undefined reference<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/da8120aa7e6cee6dc8c7912b2b7afba7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAntonio Banderas<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/635c3ea0c7b8c37ef45744b6e66dd263?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nxtofl<br \/>\nc++ exception-handling googletest<br \/>\nStarting to use the googletest ASSERT_THROW clause, it seems that &#8216;sometimes&#8217; the base type of the thrown exception is handled. I reduced the relevant code section to this:\/\/ myexception.h struct myexception : public std::logic_error {myexception(const char* what):std::l<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/74758c702067a3490094451e475e28c5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nprosseek<br \/>\nstl clang googletest clang++<br \/>\nI downloaded the gtest 1.6, and compiled it with clang++. export CC=\/usr\/bin\/clang export CXX=\/usr\/bin\/clang++ configure makeI got the libgtest.a, and I copied it into \/usr\/local\/lib\/libgtest_clang.a. When I tested with simple C++ code, everything works OK, however, when I tried to use vector in test code, I got these error messages in the build process. Compilation works fine. Undefined symbols for architecture x86_64:&#8221;std::basic_string<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:38:43. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>gnash117 c++ testing build linker googletest I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating ld: warning: in \/usr\/local\/lib\/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)I have tried to make the issue as simple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-684","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=684"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/684\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}