Here is part of my CMakeLists.txt:
ExternalProject_Add(
subhook
GIT_REPOSITORY https://github.com/Zeex/subhook.git
GIT_TAG v0.8.2
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/subhook-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/subhook-build"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DSUBHOOK_STATIC=ON -DSUBHOOK_TESTS=OFF SUBHOOK_FORCE_32BIT=ON)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
add_executable(t_test t_test.cc)
add_dependencies(t_test subhook)
Here is my t_test.cc:
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <subhook.h>
bool success = false;
void Detoured_PushRecv(const std::string& msg) {
success = true;
}
void test(const std::string& msg) {
success = true;
}
TEST(SocketioClient, DispatcherTaskDispatch_SuccessfullyDispatch) {
subhook::Hook hook_PushRecv((void *)test, (void *)Detoured_PushRecv, subhook::HookFlag64BitOffset);
hook_PushRecv.Install();
}
I will get this error
t_test.obj : error LNK2019: unresolved external symbol __imp__subhook_new referenced in function ...
I cannot directly add
target_link_libraries(t_test subhook)
which may cause this error:
CMake Error at test/base/CMakeLists.txt:24 (target_link_libraries):
Target "subhook" of type UTILITY may not be linked into another target.
One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
executables with the ENABLE_EXPORTS property set.
Iām on windows. How can I fix this one?
Thanks everyone for reading.