kubo / plthook

Hook function calls by replacing PLT(Procedure Linkage Table) entries.
745 stars 152 forks source link

undefined reference to `plthook_open` #37

Closed skeyvin closed 2 years ago

skeyvin commented 2 years ago
#include <iostream>
#include <thread>

#include <string>

#include "plthook/plthook.h"

 int mop(void);
ssize_t recv(){

ssize_t rv = mop();
return rv;
};

int main(){
    plthook_t *hook;
    plthook_open(&hook, "vulkan.elf");
   recv();

};

where i get

/usr/bin/ld: /tmp/ccjaXJTy.o: in function `recv()':
main.cpp:(.text+0x9): undefined reference to `mop()'
/usr/bin/ld: /tmp/ccjaXJTy.o: in function `main':
main.cpp:(.text+0x42): undefined reference to `plthook_open'
collect2: error: ld returned 1 exit status

thesame with plthook_open_by_address i tried compiling it including the plthook_elf.c and got

plthook_elf.c: In function ‘int plthook_open_real(plthook_t**, link_map*)’:
plthook_elf.c:655:26: error: invalid conversion from ‘void*’ to ‘plthook_t*’ {aka ‘plthook*’} [-fpermissive]
  655 |     *plthook_out = malloc(sizeof(plthook_t));
      |                    ~~~~~~^~~~~~~~~~~~~~~~~~~
      |                          |
      |                          void*

any help? compiling with g++

kubo commented 2 years ago

This isn't a plthook issue. This is a basic question about C/C++ programming.

If your source file name is your-program.cpp,

$ gcc -c plthook_elf.c                              # This creates plthook_elf.o.
$ g++ -c your-program.cpp                           # This creates your-program.o.
$ g++ -o your-program your-program.o plthook_elf.o  # This links your-program.o and plthook_elf.o and creates your-program.