Googletest CMAKE using library including library !

Hello,
I do have the following workspace structure structure
C:/Workspace/Project1
C:/Workspace/Project1/file1.c
C:/Workspace/Project1/file1.h
C:/Workspace/Project1/unit_test.cpp
C:/Workspace/externalLib/
C:/Workspace/Project1/googletest

The goal is the unit_test is testing “function_to_test” defined in file1.c. But this function also calls an external function (lib1_fucntion) defined in the library C:/Workspace/externalLib/lib1.lib

So My CMake definition includes:

include_directories (googletest)
include_directories(C:/Workspace/Project1)
enable_testing()
add_subdirectory(googletest)

set (Headers file1.h)
set (Sources file1.c )
set(CMAKE_CXX_FLAGS_DEBUG “${CMAKE_CXX_FLAGS_DEBUG} /MTd”)
add_library (file_1_libray ${Sources} ${Headers})
target_link_libraries(file_1_libray “C:/Workspace/externalLib/lib1.lib”)

add_executable( runUnitTests unit_test.cpp )
target_link_libraries(runUnitTests gtest gtest_main)
target_link_libraries(runUnitTests file_1_library )

My issue is that when building the unit_test.obj, it can not resolve the symbol function_to_test.

What am i missing in my CMakeLists.txt deifnition?

I don’t want to give unnecessary/confusing answers or ideas, so I’d first like to better understand the project setup:

  1. What header files are included in unit_test.cpp?
  2. Where is function_to_test declared?

Alain , here is more details :
In unit_test.cpp , the header is
#include <gtest/gtest.h>
#include “file1.h”

and function_to_test is decalred in file1.c and also in file1.h.
For instance , function_to_test is calling funct_libray1 provided in the library C:/Workspace/externalLib/lib1.lib
I was wondering if it is still possible to perform a unit test on a function_to_test that needs and external library to be used.
Or should i also defined mocked/stubs for the fucntion defined in this external library or refactor the code?

What is the exact error (including error code and error message) from the compiler/linker?

The error is
error LNK2019: unresolved external symbol function_to_test referenced in function "private: virtual void
__cdecl TestMyClass_First_Test::

Are you certain the definition of function_to_test in file1.c matches its declaration in file1.h?

Also, I noticed something odd in your first post. In

you are specifying file_1_libray, with a single r. But in

you are using file_1_library, with two r.

Also, since this seems to be Windows: maybe you build it as a DLL (if BUILD_SHARED_LIBS is ON) and forgot to dllexport?