Reputation: 599
I'm pretty new to working with third party stuff and also new to working on Windows with C.
I'm currently trying to simply use and include this third party library.
I've downloaded it and put all the files in include/subhook/
next to my main file.
My main.c
looks like the example on the github page, except it includes include/subhook/subhook.h
:
#include <stdio.h>
#include "include/subhook/subhook.h"
subhook_t foo_hook;
void foo(int x) {
printf("real foo just got called with %d\n", x);
}
void my_foo(int x) {
subhook_remove(foo_hook);
printf("foo(%d) called\n", x);
foo(x);
subhook_install(foo_hook);
}
int main() {
foo_hook = subhook_new((void *)foo, (void *)my_foo, 0);
subhook_install(foo_hook);
foo(123);
subhook_remove(foo_hook);
subhook_free(foo_hook);
}
and this is my CMakeLists.txt file. I've also tried including all the other .c files but it won't work:
cmake_minimum_required(VERSION 3.7)
project(NexusHookSubhook)
set(CMAKE_C_STANDARD 11)
include_directories(include/subhook)
set(SOURCE_FILES main.c include/subhook/subhook.h include/subhook/subhook.c)
add_executable(NexusHookSubhook ${SOURCE_FILES})
When I try to compile I get a whole load of these errors (which is, I assume, from linking/including the library wrong). Can anyone explain what I'm doing wrong here?
C:\Users\Nakroma\.CLion2017.1\system\cygwin_cmake\bin\cmake.exe --build C:\Users\Nakroma\CLionProjects\NexusHookSubhook\cmake-build-debug --target NexusHookSubhook -- -j 4
[ 33%] Linking C executable NexusHookSubhook.exe
CMakeFiles/NexusHookSubhook.dir/main.c.o: In function `my_foo':
/cygdrive/c/Users/Nakroma/CLionProjects/NexusHookSubhook/main.c:12: undefined reference to `__imp_subhook_remove'
/cygdrive/c/Users/Nakroma/CLionProjects/NexusHookSubhook/main.c:12:(.text+0x3c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_subhook_remove'
/cygdrive/c/Users/Nakroma/CLionProjects/NexusHookSubhook/main.c:17: undefined reference to `__imp_subhook_install'
/cygdrive/c/Users/Nakroma/CLionProjects/NexusHookSubhook/main.c:17:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_subhook_install'
CMakeFiles/NexusHookSubhook.dir/main.c.o: In function `main':
/cygdrive/c/Users/Nakroma/CLionProjects/NexusHookSubhook/main.c:21: undefined reference to `__imp_subhook_new'
....
Additional notes: I'm on Windows 10 with Cygwin 2.8.0 and CMake 3.7.2 (using the make and gcc package and GDB 7.11.1)
Upvotes: 1
Views: 1679
Reputation: 159
you totally miss the linking part in your CMakeFiles
target_link_libraries(
NexusHookSubhook
${subhookLib}
m
)
Where subhookLib is the library of subhook.
Upvotes: 1
Reputation: 166
I would recommend the following things:
Replace
#include "include/subhook/subhook.h"
with
#include "subhook.h"
as first part of the path is already included over here:
include_directories(include/subhook)
Only include the .c files as SOURCE_FILES:
set(SOURCE_FILES main.c include/subhook/subhook.c)
Upvotes: 0