bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.47k stars 582 forks source link

Windows Development - Use GCC compiler #598

Closed benshiffman closed 2 years ago

benshiffman commented 2 years ago

I've had great success on Linux with javacpp, but my particular library doesn't play nice with Windows' CL compiler. I'm attempting to use Cygwin with gcc to run javacpp on my generated class file to create the JNI mappings, but it's still looking for cl.exe. Is there a way to specify a compiler for javacpp to use?

Update: I discovered the -Dplatform.compiler=gcc flag, but running into another issue: it seems that none of the include paths are working because of the path format of the Cygwin/mintty terminal I'm using. Even files within my project folder are not found. Is there perhaps another flag to specify working directory path?

saudet commented 2 years ago

There are properties for MinGW: https://github.com/bytedeco/javacpp/tree/master/src/main/resources/org/bytedeco/javacpp/properties On the command line, we can use those with something like java -jar javacpp.jar -properties windows-x86_64-mingw, but if you need to modify those properties, we can specify a file instead, like java -jar javacpp.jar -propertyfile /path/to/your/windows-x86_64.properties. Does that answer your question?

benshiffman commented 2 years ago

Hi @saudet, so sorry it's taken so long to get back. I've installed mingw64 and tried many configurations using the flag you mentioned, but I'm still coming up with the same error shown in the attached screenshot. errormsg

It seems there's a dependency on mingw64's dlfcn library which I haven't been able to resolve by installing any of the packages listed here.

Is there something I'm overlooking?

saudet commented 2 years ago

It looks like you're trying to use compilers for Cygwin, that won't work with JavaCPP, we need to use compilers for MinGW, for example, the ones here: https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments#windows-x86-and-x86_64

benshiffman commented 2 years ago

After configuring MSYS and running javacpp through mingw64 (both via the mingw64 shell and the Native Tools Command Prompt) the above errors have disappeared, but I'm getting a bunch of undefined references to most of my library's functions. I wish I could provide a screenshot but I am working with controlled information here. I should mention that I'm not working with javacpp-presets; I'm following Mapping Recipes.

saudet commented 2 years ago

If your library requires Cygwin to run on Windows, that's going to be hard, if not impossible, to get working with JNI. You might need to start looking at other options like sockets and what not.

benshiffman commented 2 years ago

I gave CL.exe another crack and finally found the root of the errors. There was a missing 3rd party library which cl didn't make very apparent. Compiled with ease!

Thanks again for being so active here, this is really an amazing piece of software!