Difference between revisions of "Duby/Capstone"

From havefunsoft wiki
Jump to: navigation, search
m (Static Linking)
m (Compiling with Mingw (32 or 64))
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
  
==Compiling with Mingw==
+
==Compiling with Mingw (32 or 64)==
 
The default compilation doesn't work and fails with a linking error:
 
The default compilation doesn't work and fails with a linking error:
 
  ./arch/Sparc/SparcInstPrinter.o:SparcInstPrinter.c:(.text+0x4e0): multiple definition of `imaxabs'
 
  ./arch/Sparc/SparcInstPrinter.o:SparcInstPrinter.c:(.text+0x4e0): multiple definition of `imaxabs'
Line 13: Line 13:
 
  CFLAGS="-llibmingwex" ./make.sh gcc
 
  CFLAGS="-llibmingwex" ./make.sh gcc
 
Adding libmingwex library for compilation prevents imaxabs to be inserted into .o file (because the function is implemented in mingwex)
 
Adding libmingwex library for compilation prevents imaxabs to be inserted into .o file (because the function is implemented in mingwex)
 +
 +
 +
For x64, there's [https://sourceforge.net/projects/mingw-w64/ Mingw-64 project]. After building static library is renamed into "capstone.lib" (even though it should be named "libcapstone.a").
 +
(Presumably, there's a hard-coded rule, if Windows and 64-bit platform, follow MS VS standards)
  
 
==Static Linking==
 
==Static Linking==

Latest revision as of 11:16, 31 October 2017

Capstone Engine is an open source library for disassembly.


Compiling with Mingw (32 or 64)

The default compilation doesn't work and fails with a linking error:

./arch/Sparc/SparcInstPrinter.o:SparcInstPrinter.c:(.text+0x4e0): multiple definition of `imaxabs'
./arch/PowerPC/PPCInstPrinter.o:PPCInstPrinter.c:(.text+0x16030): first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [libcapstone.so] Error 1

(for whatever reason "imaxabs" is included in resulting files as a stand-alone function, rather than inline function)

The following command line should be used to compile the library on MinGW (with gcc installed)

CFLAGS="-llibmingwex" ./make.sh gcc

Adding libmingwex library for compilation prevents imaxabs to be inserted into .o file (because the function is implemented in mingwex)


For x64, there's Mingw-64 project. After building static library is renamed into "capstone.lib" (even though it should be named "libcapstone.a"). (Presumably, there's a hard-coded rule, if Windows and 64-bit platform, follow MS VS standards)

Static Linking

Once the static library is built, it's possible to link it statically to the executable. However, there are certain dependencies that must be resolved first.

 {$linklib libcapstone} // library itself
 {$ifdef mswindows}
 {$linklib libmsvcrt}   // MS Visual C runtime (mingw bindings)
 {$linklib libgcc}      // C++ library
 {$endif}

Such dependencies are pretty typical for mingw compilation.

See Also