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

Native build: JAVA_HOME auto-detection yields double-quoted value #244

Open
MrDOS opened this issue Sep 5, 2023 · 0 comments
Open

Native build: JAVA_HOME auto-detection yields double-quoted value #244

MrDOS opened this issue Sep 5, 2023 · 0 comments
Assignees
Milestone

Comments

@MrDOS
Copy link
Contributor

MrDOS commented Sep 5, 2023

When attempting to compile the native libraries in a Windows environment, I get a “No such file or directory” error:

C:\Users\scoleman\Projects\nrjavaserial>mingw32-make -C src/main/c windows
mingw32-make: Entering directory 'C:/Users/scoleman/Projects/nrjavaserial/src/main/c'
JAVA_HOME.mk:112: The JAVA_HOME environment variable has not been defined.
Based on the location of the `java` binary, I've guessed it's:

    "C:\Program Files\Eclipse Adoptium\jdk-17.0.8.7-hotspot"

If that's not correct, or to suppress this message, explicitly set the
JAVA_HOME environment variable to the location of your preferred Java
installation.
mingw32-make -f natives.mk
mingw32-make[1]: Entering directory 'C:/Users/scoleman/Projects/nrjavaserial/src/main/c'
x86_64-w64-mingw32-gcc -I""C:\Program Files\Eclipse Adoptium\jdk-17.0.8.7-hotspot"/include" -I./include -I./include/target -O3 -fPIC -c -Wall -I./include/windows -I./include/windows/win32 -m32 src/fixup.c -o build/windows/x86_32/fixup.o
x86_64-w64-mingw32-gcc: error: Files\Eclipse: No such file or directory
x86_64-w64-mingw32-gcc: error: Adoptium\jdk-17.0.8.7-hotspot/include: No such file or directory
natives.mk:15: recipe for target 'build/windows/x86_32/fixup.o' failed
mingw32-make[1]: *** [build/windows/x86_32/fixup.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/scoleman/Projects/nrjavaserial/src/main/c'
Makefile:292: recipe for target 'windows32' failed
mingw32-make: *** [windows32] Error 2
mingw32-make: Leaving directory 'C:/Users/scoleman/Projects/nrjavaserial/src/main/c'

I'm using GNU Make 3.82.90 as packaged with TDM-GCC 10.3.0-2. The detected Java path is correct. The problem appears to be double-quoting in the include path:

-I""C:\Program Files\Eclipse Adoptium\jdk-17.0.8.7-hotspot"/include"

The doubling-up of the first quotation marks causes this to be interpreted as three arguments, not one.

The inner set of quotes are put there by the path detection:

JAVA_HOME := "$(subst ?,$(space),$(JAVA_HOME))"

This is not a Windows-specific issue. The double-quoting also occurs on Linux:

$ make -C src/main/c linux32
make: Entering directory '/home/scoleman/Projects/nrjavaserial/src/main/c'
JAVA_HOME.mk:112: The JAVA_HOME environment variable has not been defined.
Based on the location of the `java` binary, I've guessed it's:

    "/usr/lib/jvm/java-17-openjdk-amd64"

...
i686-linux-gnu-gcc -I""/usr/lib/jvm/java-17-openjdk-amd64"/include" -I./include -I./include/target -O3 -fPIC -c -Wall -I"/usr/lib/jvm/java-17-openjdk-amd64"/include/linux -U_FORTIFY_SOURCE -m32 src/SerialImp.c -o build/linux/x86_32/SerialImp.o
...

...but it doesn't cause a problem there, because the Java home doesn't contain spaces.

The outer quotes were added in #231 because @fwolter ran into issues with their absence. I suspect that Fabian had/has the JAVA_HOME environment variable explicitly defined in his environment; because the value was not quoted at time of use, he got much the same error as I'm getting now. The root cause here is that I must've neglected to test building with JAVA_HOME explicitly set to a path containing spaces while refactoring the build process in #189. The full solution is to remove the inner quotes added during path detection, and to make sure $(JAVA_HOME) is quoted wherever it's used in the main Makefile.

@MrDOS MrDOS added this to the v5.3.0 milestone Sep 5, 2023
@MrDOS MrDOS self-assigned this Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant