Linking errors in C ++

0

Hello I am trying to compile my project using an additional library first I generate the compiled code of my program:

gcc -o programa.exe Dynamic.cpp

Then I add the library to my program:

g++ -o programa.exe Dynamic.o hook.o 

But it shows me the following errors:

hook.o:hook.c:(.text+0xa2c): undefined reference to 'InitializeBuffer'
hook.o:hook.c:(.text+0xa7d): undefined reference to 'UninitializeBuffer'
hook.o:hook.c:(.text+0xb14): undefined reference to 'IsExecutableAddress'
hook.o:hook.c:(.text+0xb27): undefined reference to 'IsExecutableAddress'
hook.o:hook.c:(.text+0xb52): undefined reference to 'AllocateBuffer'
hook.o:hook.c:(.text+0xb7c): undefined reference to 'CreateTrampolineFunction'
hook.o:hook.c:(.text+0xca0): undefined reference to 'FreeBuffer'
hook.o:hook.c:(.text+0xd82): undefined reference to 'FreeBuffer'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: hook.o: bad reloc address 0x13c in section '.rdata'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

To solve it I need to link to the buffer library as I show in the capture attempt to do following the steps indicated but it did not work:

I recommend using msys or cmake since the codeblocks version is a bit old or updating it to a new version.

    
asked by Sergio Ramos 14.03.2017 в 22:18
source

2 answers

1

If the library is not in the default path of the compiler you have to indicate the path explicitly so that the compiler can find it:

Option 1:

g++ -o ... -L[ruta_libreria]/[nombre_libreria]

Option 2:

g++ -o ... -L[ruta_libreria] -l[nombre_libreria]

As for what libraries you need ... you should check the list of dependencies of your sources and static libraries. We can not help you in that.

    
answered by 15.03.2017 / 09:50
source
0

Install msys that includes a collection of all las dependencias necesaria s. Supplement to las deficiencias en consola (since Mingw uses an outdated version ( TDM-GCC 4.9.2 SJLJ (released in October 30, 2014) ) and I guess it will not include it by default.

To solve it I did:

g++ -o bot.exe Dynamic.o hook.o -L/c/"ruta"/ trampoline.a buffer.a hde32.a
    
answered by 15.03.2017 в 15:30