naviqore / jni-cpp-testing

exploring and testing the integration of Java and C++ using the Java Native Interface (JNI)
MIT License
0 stars 0 forks source link

Compile cxx project on mac #7

Open Brunner246 opened 1 month ago

Brunner246 commented 1 month ago

Please try if the project compiles on mac. =)

https://github.com/naviqore/jni-cpp-testing

munterfi commented 1 month ago

In Clion, unfortunately not 😅

====================[ Build | cpp_lib | Debug ]=================================
/Applications/CLion.app/Contents/bin/cmake/mac/x64/bin/cmake --build /Users/munterfi/repos/naviqore/jni-cpp-testing/cmake-build-debug --target cpp_lib -j 14
[1/2] Building CXX object CMakeFiles/cpp_lib.dir/src/library.cpp.o
FAILED: CMakeFiles/cpp_lib.dir/src/library.cpp.o 
/usr/bin/g++ -DLIBRARY_EXPORTS -Dcpp_lib_EXPORTS -I/include/darwin -I/include -g -std=gnu++20 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -fPIC -fcolor-diagnostics -MD -MT CMakeFiles/cpp_lib.dir/src/library.cpp.o -MF CMakeFiles/cpp_lib.dir/src/library.cpp.o.d -o CMakeFiles/cpp_lib.dir/src/library.cpp.o -c /Users/munterfi/repos/naviqore/jni-cpp-testing/src/library.cpp
In file included from /Users/munterfi/repos/naviqore/jni-cpp-testing/src/library.cpp:1:
/Users/munterfi/repos/naviqore/jni-cpp-testing/src/library.h:5:10: fatal error: 'jni.h' file not found
#include "jni.h"
         ^~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
munterfi commented 1 month ago

And if I don't enforce ninja and use make instead:

====================[ Build | cpp_lib | Debug ]=================================
/Applications/CLion.app/Contents/bin/cmake/mac/x64/bin/cmake --build /Users/munterfi/repos/naviqore/jni-cpp-testing/cmake-build-debug --target cpp_lib -- -j 14
[ 50%] Building CXX object CMakeFiles/cpp_lib.dir/src/library.cpp.o
In file included from /Users/munterfi/repos/naviqore/jni-cpp-testing/src/library.cpp:1:
/Users/munterfi/repos/naviqore/jni-cpp-testing/src/library.h:5:10: fatal error: 'jni.h' file not found
#include "jni.h"
         ^~~~~~~
1 error generated.
make[3]: *** [CMakeFiles/cpp_lib.dir/src/library.cpp.o] Error 1
make[2]: *** [CMakeFiles/cpp_lib.dir/all] Error 2
make[1]: *** [CMakeFiles/cpp_lib.dir/rule] Error 2
make: *** [cpp_lib] Error 2
munterfi commented 1 month ago

Do I need to export some INCLUDES for Java?

Brunner246 commented 1 month ago

@munterfi the issue is that the header to the JNI interfaces can not be found

'jni.h' file not found
#include "jni.h"

can you verify that the headers are located in

elseif (APPLE)
    include_directories("$ENV{JAVA_HOME}/include/darwin")
    include_directories("$ENV{JAVA_HOME}/include/")

?