{"record":{"id":"30081c98c0430fbb","repo":"java-native-access/jna","slug":"error-looking-up-symbolname-e-getmessage","errorCode":null,"errorMessage":"Error looking up 'symbolName': e.getMessage()","messagePattern":"Error looking up 'symbolName': e\\.getMessage\\(\\)","errorType":"exception","errorClass":"java.lang.UnsatisfiedLinkError","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/NativeLibrary.java","lineNumber":639,"sourceCode":"            return function;\n        }\n    }\n\n    /** @return this native library instance's options. */\n    public Map<String, ?> getOptions() {\n        return options;\n    }\n\n    /** Look up the given global variable within this library.\n     * @param symbolName\n     * @return Pointer representing the global variable address\n     * @throws UnsatisfiedLinkError if the symbol is not found\n     */\n    public Pointer getGlobalVariableAddress(String symbolName) {\n        try {\n            return new Pointer(getSymbolAddress(symbolName));\n        } catch(UnsatisfiedLinkError e) {\n            throw new UnsatisfiedLinkError(\"Error looking up '\" + symbolName + \"': \" + e.getMessage());\n        }\n    }\n\n    /**\n     * Used by the Function class to locate a symbol\n     * @throws UnsatisfiedLinkError if the symbol can't be found\n     */\n    long getSymbolAddress(String name) {\n        if (handle == 0) {\n            throw new UnsatisfiedLinkError(\"Library has been unloaded\");\n        }\n        return this.symbolProvider.getSymbolAddress(handle, name, NATIVE_SYMBOL_PROVIDER);\n    }\n\n    @Override\n    public String toString() {\n        return \"Native Library <\" + libraryPath + \"@\" + handle + \">\";\n    }","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/NativeLibrary.java#L621-L657","documentation":"NativeLibrary.getGlobalVariableAddress rethrows an UnsatisfiedLinkError from symbol lookup wrapped as \"Error looking up '<symbol>': <original message>\". It means the named global variable/symbol could not be resolved in the loaded native library.","triggerScenarios":"Calling lib.getGlobalVariableAddress(\"symbol\") where the symbol does not exist, the library was loaded but exports it under a different (e.g. mangled or versioned) name, or the symbol is in a dependency library.","commonSituations":"Typo in symbol name; symbol only exported with C++ name mangling; using headers from a different library version than the loaded binary; static library symbols stripped by the linker.","solutions":["Verify the symbol is exported: nm -D libfoo.so | grep symbol (or dumpbin/otool)","Check for C++ name mangling; declare extern \"C\" in the native code or use the mangled name","Confirm the loaded library version matches the headers you coded against","Read the nested e.getMessage() in the error text for the underlying cause"],"exampleFix":"// before\nPointer p = lib.getGlobalVariableAddress(\"errno_value\");\n// after\n// verify with: nm -D libfoo.so | grep errno\nPointer p = lib.getGlobalVariableAddress(\"errno\"); // actual exported name","handlingStrategy":"try-catch","validationCode":"// confirm export beforehand:\n// nm -D libfoo.so | grep <symbolName>\nif (symbolName == null || symbolName.isEmpty()) throw new IllegalArgumentException(\"symbolName required\");","typeGuard":null,"tryCatchPattern":"try {\n    Pointer p = lib.getGlobalVariableAddress(\"mySymbol\");\n} catch (UnsatisfiedLinkError e) {\n    // symbol missing/mangled; parse e.getMessage() for the inner cause\n}","preventionTips":["Check exports with nm -D / dumpbin before coding the lookup","Use extern \"C\" in native code to avoid C++ mangling","Keep native headers and binary versions in sync"],"tags":["jna","symbol-lookup","unsatisfiedlinkerror","native-library"],"backgroundTag":"resource-not-found","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}