Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:26:16+00:00 2026-05-30T06:26:16+00:00

I have a C makefile which generates header file from java code and compiles

  • 0

I have a C makefile which generates header file from java code and compiles very simple C executable file. There is an error which I can’t find. When I try to run the code I get UnsatisfiedLinkError.

This is the content of the makefile:

#!/usr/bin/make -f
#
# Makefile for native stuff
#

# c files to compile
C_SOURCES   := sqrt.c

# the name of the library to build
LIBNAME     := sqrt

C_SOURCE_DIR    := src
C_GENSOURCE_DIR := src

TARGET_DIR  := ../../../target
C_BUILD_DIR    = $(TARGET_DIR)/native
JAVA_BUILD_DIR = $(TARGET_DIR)/classes

# the name of the file we build
TARGET      = $(JAVA_BUILD_DIR)/META-INF/lib/$(LIB_PREFIX)$(LIBNAME)$(LIB_EXTN)

# find the jdk. if this doesn't work for you, define JAVA_HOME in your
# environment or on the make command line
JAVA_HOME ?= /opt/jdk1.7.0_02

# classpath for javah
JAVAH_CLASSPATH = `cat $(TARGET_DIR)/compile-classpath`

# tools and options
CFLAGS = -Wall -fpic
CPPFLAGS = -I$(C_SOURCE_DIR) -I$(C_GENSOURCE_DIR) -Iinclude \
    -I$(JAVA_HOME)/include
JAVAH = /opt/jdk1.7.0_02/bin/javah
JAVAH_FLAGS += -classpath $(JAVAH_CLASSPATH)
JAVAH_CMD = $(JAVAH) $(JAVAH_FLAGS) $(OUTPUT_OPTION)
LDFLAGS = -shared
LINK.so = $(CC) $(LDFLAGS) $(LD_LIBS)

ifdef DEBUG
CFLAGS += -g
LDFLAGS += -g
endif

# os-dependent bits
UNAME := $(shell uname)

ifeq ($(UNAME),Linux)
LIB_PREFIX = lib
LIB_EXTN = .so
CPPFLAGS += -I$(JAVA_HOME)/include/linux
else
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
LIB_PREFIX =
LIB_EXTN = .dll
CPPFLAGS += -I$(JAVA_HOME)/include/win32
else
f := $(error Platform $(UNAME) not supported)
endif
endif

# we look in $(C_SOURCE_DIR) for c files...
vpath %.c $(C_SOURCE_DIR)

# convenience variables
C_OBJFILES = $(addprefix $(C_BUILD_DIR)/,$(subst .c,.o,$(C_SOURCES)))

# default target
all: $(TARGET)

# rule to compile the .c files
$(C_BUILD_DIR)/%.o: %.c
    @mkdir -p `dirname $@`
    $(COMPILE.c) $(OUTPUT_OPTION) $<

# link the C objects into a shared library
$(TARGET): $(C_OBJFILES) $(LDLIBS)
    @mkdir -p `dirname $@`
    $(LINK.so) $(OUTPUT_OPTION) $^

# a rule to build the .h file with javah                    
$(C_GENSOURCE_DIR)/org_DX_57_osgi_NB_27_impl_Sqrt.h: $(JAVA_BUILD_DIR)/org/DX_57/osgi/NB_27/impl/Sqrt.class
    rm -f $@                
    $(JAVAH) $(JAVAH_FLAGS) $(OUTPUT_OPTION) org.DX_57.osgi.NB_27.impl.Sqrt

# the .o file depends on the .h file
$(C_BUILD_DIR)/sqrt.o: $(C_GENSOURCE_DIR)/org_DX_57_osgi_NB_27_impl_Sqrt.h

clean::
    rm -f $(C_OBJFILES)
    rm -f $(TARGET)
    rm -f $(C_BUILD_DIR)/jnirules.mak

Here is the content of the C file:

#include "org_DX_57_osgi_NB_27_impl_Sqrt.h"

JNIEXPORT jdouble JNICALL Java_Sqrt_sqrt
(JNIEnv *env, jclass cls, jdouble d, jdouble tol)
{

    return tol;
}

Best wishes
Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:26:17+00:00Added an answer on May 30, 2026 at 6:26 am

    UnsatisfiedLinkError means the JVM failed to load the native shared object that the makefile produced, or .so that the native shared object depends on.

    Adding absolute path of ../../../target/native to LD_LIBRARY_PATH will enable the JVM to locate the .so. If the .so depends on other .so libraries the directories where these .so exist will also need added to LD_LIBRARY_PATH.

    EDIT:

    Instead of ../../../target/native use absolute path of NB_27-impl/target/classes/lib.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to create a Makefile.am file which generates one header file mentioned in
I have a Makefile from which I want to call another external bash script
I have a Makefile rule that generates an MD5 hash for a file, compares
If you have a project that utilizes a makefile which compiles multiple files and
In my makefile I have the following target, which compiles text/HTML resources into unsigned
We have a Makefile which runs on a Windows 2003 machine and we are
So, I have a Makefile which runs different commands of how to build S/W.
In a makefile, I have the following line: helper.cpp: dtds.h Which ensures that helper.cpp
I'm new to the world of Makefile writing. I have a C project which
I have a makefile that depending on some properties sets vpath and generates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.