spotify / JniHelpers

Tools for writing great JNI code
Apache License 2.0
595 stars 112 forks source link

make error in linux #14

Open QiYueFeiXue opened 7 years ago

QiYueFeiXue commented 7 years ago

hello, I followed your comand line, but find this error: JniHelpers/src/test/cpp/NativeObjectTest.cpp:49:24: error: ‘TEST_INTEGER’ was not declared in this scope

dongjinleekr commented 6 years ago

I also experienced the same problem. For the other people who encountered this problem, here is the solution: Just re-generate test constants definition file with following commands:

src/test/bin/generate_test_constants.sh src/test/data/TestConstants.txt src/test/cpp/TestConstants.h src/test/java/com/spotify/jni/TestConstants.java

This command generates TestConstants.h and TestConstants.java which defines TEST_INTEGER etc from TestConstants.txt. Originally, they are not included in the source tree so you need to generate them. It sometimes generated improperly (I don't know why) so you need to regenerate them.

After giving above commands, You can now build the project without any problem.

nanmi commented 3 years ago

It sometimes generated improperly, if you build failed, you should add manually like: `#define TEST_STRING "hello, is it me you're looking for?"

define TEST_NULL_CHAR "\0"

define TEST_STRING_WITH_NULL_CHAR "hello \0 world"

define TEST_UTF16_STRING u"UTF16 hello: \u2018."

define TEST_UTF8_STRING u8"a \u0915\u093E\u091A\u0902 \u00F6 1 2 3"

define TEST_INTEGER 42

define TEST_SHORT 777

define TEST_BOOLEAN true

define TEST_FLOAT 3.14159f

define TEST_FLOAT_TOLERANCE 0.01

define TEST_DOUBLE 2.71828

define TEST_BYTE 72

// #define TEST_CHAR 'ö' JAVA

define TEST_CHAR 'a'`

public class TestConstants { public static final String TEST_STRING = "hello, is it me you're looking for?"; public static final String TEST_NULL_CHAR = "\0"; public static final String TEST_STRING_WITH_NULL_CHAR = "hello \0 world"; public static final String TEST_UTF16_STRING = "UTF16 hello: \u2018."; public static final String TEST_UTF8_STRING = "a \u0915\u093E\u091A\u0902 \u00F6 1 2 3"; public static final int TEST_INTEGER = 42; public static final short TEST_SHORT = 777; public static final boolean TEST_BOOLEAN = true; public static final float TEST_FLOAT = 3.14159f; public static final double TEST_FLOAT_TOLERANCE = 0.01; public static final double TEST_DOUBLE = 2.71828; public static final byte TEST_BYTE = 72; public static final char TEST_CHAR = 'a'; // public static final char TEST_CHAR L'ö' CPP } in src/test/cpp/TestConstants.h and src/test/java/com/spotify/jni/TestConstants.java

also, you should add JNI_INCLUDE_DIRS JNI_LIBRARIES environment variable