Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using libuiohook library dynamically #51

Closed
ufoscout opened this issue May 25, 2017 · 9 comments
Closed

Using libuiohook library dynamically #51

ufoscout opened this issue May 25, 2017 · 9 comments
Labels

Comments

@ufoscout
Copy link

Hi @kwhat

I would like to use your library from a golang application. I have no knowledge of C so I have extracted the the compiled version of this library from the jnativehook.jar file. However, to use them I need the related header files and I don't which one to use. Could you please help me identifying the correct ones?

@kwhat
Copy link
Owner

kwhat commented May 25, 2017

Hi @ufoscout,

I have no idea how to use a C library with GoLang ;) I do know that you cannot use the binary from JNativeHook because it has been linked against the Java runtime. You should be able to compile this library using autotools without to much trouble. For more compilation instructions, you can follow the Wiki article from JNativeHook and just skip the Java portions. Let me know if you have issues or need further assistance.

Best,
Alex

@kwhat kwhat added the question label May 25, 2017
@kwhat
Copy link
Owner

kwhat commented May 25, 2017

P.S. The binary public interface you are looking for is uiohook.h

@ufoscout
Copy link
Author

Hi @kwhat
the wiki page you linked explains how to build JNativeHook with ant, but if follow that process don't have I the same issue you mentioned about the library being linked against the Java runtime?

@kwhat
Copy link
Owner

kwhat commented May 25, 2017

You dont need the ant part, just the dependencies like gcc or other C99 compiler, autotools, pkgconfig & libtool for your platform. After you have installed what is required for your platform, you should be able to run the 3 commands in the read me to compile. All of the default options will be selected for you; you can customize the build using --enable / --disable or --with / --without. Use ./configure --help for a list of options.

./bootstrap.sh
./configure
make

@ufoscout
Copy link
Author

Hi @kwhat
thanks for your help, I was able to compile it on my machine and to link it dynamically.
I saw that the build instructions for JNativeHook include cross compilation options; is it possible to crosscompile this library passing some special flags to the make file?
For example, something like:

./bootstrap.sh
./configure
make --target=windows

@kwhat
Copy link
Owner

kwhat commented May 27, 2017

Hi @ufoscout,

Cross compiling is far more challenging than targeting your local platform. Lets start with the easy stuff, you can switch between x86 / amd64 on a 64 bit system that supports 32 bit execution with -m. For compiling between platforms (Ex: from Windows to OS X) you will need the development headers and libraries for that platform in the architecture you are targeting. Note, this is easier on some platforms and difficult on others. After you have the required development libraries installed, you will need a compiler that can target (build for) the architecture you want to build for. Usually this compiler is compiled from source to run on one architecture and compile programs for another. GCC is the most commonly used, although technically any compiler would do. For example, I also use LLVM+CLANG to target OS X. Finally, you will need a linker that can create the container format required. Binutils provides a linker for most Linux supported architectures, MinGw will provide most of your Gcc for Windows needs and finally I use a Linux ported version of Apple open source linker from XCode Tools. https://github.com/kwhat/binutils-apple

I do most of my cross compiling on Gentoo Linux as they have many tools to help with this process, some of which are also in my repository.

Hope that helps.
Alex

@ufoscout
Copy link
Author

ufoscout commented May 29, 2017

Hi @kwhat

you are providing a great support but I understood that cross compiling is too far from my actual level...
However, thanks to your help I was able to compile it on Windows and Linux. Here a step by step beginner guide to compile this library in Windows if someone needs it:

  • Download and install msys2 ( http://www.msys2.org/ )
  • Open the msys2 console
  • Update the package database and core system packages:
    pacman -Syu
  • Update other packages (better to restart before):
    pacman -Su
  • Install required packages:
    pacman -S autoconf automake-wrapper gcc libtool make pkg-config git
  • clone the uiohook repository somewhere:
    git clone https://github.com/kwhat/libuiohook.git
  • enter the libuiohook folder and start the build process:
    ./bootstrap
    ./configure
    make
    
  • the build library is in the .libs folder

One question:

you can switch between x86 / amd64 on a 64 bit system that supports 32 bit execution with -m

how should I use the "-m" option? something like: make -m32?

@ufoscout
Copy link
Author

Now I have another issue :(
When I use the dll that I build on Windows, it fails with this error message:
"The program can't start because msys-2.0.dll" is missing from your computer"
I guess that this means that if I compile it in MSYS2 then I can use it only in MSYS2, am I wrong? How can I build it in a portable way that has no external dependency?

@kwhat
Copy link
Owner

kwhat commented May 29, 2017

Hi @ufoscout,

For the first post, you probably want to use the mingw32 and mingw64 consoles to compile. This should also solve the msys-2.0.dll problem. The -m options are just like you described.

@kwhat kwhat closed this as completed Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants