Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 793627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:10:57+00:00 2026-05-14T22:10:57+00:00

I have a simple test file, TestMe.cpp: #include <gtest/gtest.h> TEST(MyTest, SomeTest) { EXPECT_EQ(1, 1);

  • 0

I have a simple test file, TestMe.cpp:

#include <gtest/gtest.h>

TEST(MyTest, SomeTest) {
  EXPECT_EQ(1, 1);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

I have Google Test built as a static library. (I can provide the makefile if it’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 -lgtest -o TestMe.exe

It runs as expected.

However, I cannot get this to compile in Qt. My Qt project file, in the same directory:

SOURCES += TestMe.cpp
INCLUDEPATH += C:\gtest-1.5.0\gtest-1.5.0\include
LIBS += -L../gtest/staticlib -lgtest

This results in 17 “unresolved external symbol” errors related to gtest functions.

I’m pulling my hair out here, as I’m sure it’s something simple. Any ideas?

Here are some of the external symbols that are undefined:

TestMe.obj:-1: error:  unresolved external symbol "public: int __thiscall testing::UnitTest::Run(void)" (?Run@UnitTest@testing@@QAEHXZ) referenced in function _main
TestMe.obj:-1: error:  unresolved external symbol "public: static class testing::UnitTest * __cdecl testing::UnitTest::GetInstance(void)" (?GetInstance@UnitTest@testing@@SAPAV12@XZ) referenced in function _main
TestMe.obj:-1: error:  unresolved external symbol "void __cdecl testing::InitGoogleTest(int *,char * *)" (?InitGoogleTest@testing@@YAXPAHPAPAD@Z) referenced in function _main
TestMe.obj:-1: error:  unresolved external symbol "public: __thiscall testing::internal::AssertHelper::~AssertHelper(void)" (??1AssertHelper@internal@testing@@QAE@XZ) referenced in function "private: virtual void __thiscall MyTest_SomeTest_Test::TestBody(void)" (?TestBody@MyTest_SomeTest_Test@@EAEXXZ)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:10:57+00:00Added an answer on May 14, 2026 at 10:10 pm

    I never could get this to work as a static library, but it’s working as a DLL.

    First, I had to build Google Test as a DLL. I did not have any success getting this to work in Visual Studio, so I just used mingw32-make. You can use the Makefile provided in the source, making the following changes:

    gtest-all.o : $(GTEST_SRCS_)
        $(CXX) $(CPPFLAGS) -DGTEST_CREATE_SHARED_LIBRARY=1 -I$(GTEST_DIR) $(CXXFLAGS) -c \
                $(GTEST_DIR)/src/gtest-all.cc
    
    gtest_main.o : $(GTEST_SRCS_)
        $(CXX) $(CPPFLAGS) -DGTEST_CREATE_SHARED_LIBRARY=1 -I$(GTEST_DIR) $(CXXFLAGS) -c \
                $(GTEST_DIR)/src/gtest_main.cc
    
    gtest.dll : gtest-all.o
        $(CXX) -shared -o $@ $^ -Wl,--out-implib,gtest_dll.lib
    
    gtest_main.dll : gtest-all.o gtest_main.o
        $(CXX) -shared -o $@ $^ -Wl,--out-implib,gtest_main_dll.lib
    

    Then, when compiling your test project, you must:

    • Define GTEST_LINKED_AS_SHARED_LIBRARY=1
    • Set a library reference to either gtest_dll.lib or gtest_main_dll.lib.
    • Paste gtest.dll or gtest_main.dll in the same directory as your executable.

    (My understanding is that you use gtest_main only if you are NOT providing your own main() function.)

    Here is a sample Qt pro file based on the one I have this is (finally!) working:

    DEFINES += GTEST_LINKED_AS_SHARED_LIBRARY=1
    SOURCES += main.cpp MyClassTests.cpp
    INCLUDEPATH += ../path/to/gtest/includes
    LIBS += -L../path/to/gtest/libraries -lgtest_dll \
        -L../ClassLibrary/bin -lMyClass
    CONFIG += console
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is determined at the browser level, unless you moved… May 15, 2026 at 11:35 am
  • Editorial Team
    Editorial Team added an answer One option is to use sessions and another is to… May 15, 2026 at 11:35 am
  • Editorial Team
    Editorial Team added an answer Shared Access Signatures can be scoped at either a specific… May 15, 2026 at 11:35 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.