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

  • SEARCH
  • Home
  • 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 8269303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:11:00+00:00 2026-06-08T06:11:00+00:00

I’m running a basic Java wrapper for a C++ BSD socket client. I can

  • 0

I’m running a basic Java wrapper for a C++ BSD socket client. I can compile the Java and generate a header file, but when I try to run it, it returns Exception in thread "main" java.lang.UnsatisfiedLinkError: JavaClient.socketComm()V

From what I’ve been able to find, it seems like this is indicative of a mismatch between method signatures, but I can’t find anything wrong with mine.

Java Code

public class JavaClient 
{
    public native void socketComm();

    public static void main(String[] args)
    {
        System.load("/home/cougar/workspace/ArbiterBSDSocketComms/JNIClient/JavaClient.so");
        JavaClient client = new JavaClient();
        client.socketComm();

        System.out.println("Done");
    }
}

C Implementation

#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <cstdlib>
#include <stdio.h>
#include <jni.h>
#include "JavaClient.h"
#define MAXHOSTNAME 256

JNIEXPORT void JNICALL Java_JavaClient_socketComm
    (JNIEnv *env, jobject obj) {
    struct sockaddr_in remoteSocketInfo;
    struct hostent *hPtr;
    int socketHandle;
    char *remoteHost="localhost";
    int portNumber = 8080;

memset(&remoteSocketInfo, 0, sizeof(struct sockaddr_in));       //Clear structure memory

if ((hPtr = gethostbyname(remoteHost)) == NULL)             //Get sysinfo
{
    printf("System DNS resolution misconfigured.");
    printf("Error number: ", ECONNREFUSED);
    exit(EXIT_FAILURE);
}

if((socketHandle = socket(AF_INET, SOCK_STREAM, 0)) < 0)        //Create socket
{
    close(socketHandle);
    exit(EXIT_FAILURE);
}

memcpy((char *)&remoteSocketInfo.sin_addr,
        hPtr->h_addr, hPtr->h_length);                          //Load sys info into sock data structures
remoteSocketInfo.sin_family = AF_INET;
remoteSocketInfo.sin_port = htons((u_short)portNumber);         //Set port number

if(connect(socketHandle, (struct sockaddr *)&remoteSocketInfo, sizeof(struct sockaddr_in)) < 0)
{
    close(socketHandle);
    exit(EXIT_FAILURE);
}

int rc=0;
char buf[512];

strcpy(buf, "Sup server");
send(socketHandle, buf, strlen(buf)+1, 0);
}

void main(){}

Header File

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JavaClient */

#ifndef _Included_JavaClient
#define _Included_JavaClient
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     JavaClient
 * Method:    socketComm
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_JavaClient_socketComm
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Excuse some of the bad formatting, I haven’t used stackoverflow much and the code formatting is a bit sketchy.

These files all reside in /JNIClient.

I’m running Ubuntu 12.04 x64, and I have both 32- and 64-bit JDKs installed. I tried generating the .so with the 32-bit verison first, which would have been ideal, but I got an ELF mismatch, so I just went with the 64-bit so I wouldn’t have to deal with that. (Any insight on that is welcome as well.)

My process is:

$>javac JavaClient.java

$>javah JavaClient

$>cc -m64 -g -I/usr/lib/jvm/java-6-openjdk-amd64/include -I/usr/lib/jvm/java-6-openjdk-amd64/include/linux -shared JavaClient.c -o JavaClient.so

$>java JavaClient

The full error message is

Exception in thread "main" java.lang.UnsatisfiedLinkError: JavaClient.socketComm()V
    at JavaClient.socketComm(Native Method)
    at JavaClient.main(JavaClient.java:9)

$>nm JavaClient.so returns:

cougar@Wanda:~/workspace/ArbiterBSDSocketComms/JNIClient$ nm JavaClient.so
0000000000200e50 a _DYNAMIC
0000000000200fe8 a _GLOBAL_OFFSET_TABLE_
             w _Jv_RegisterClasses
0000000000200e30 d __CTOR_END__
0000000000200e28 d __CTOR_LIST__
0000000000200e40 d __DTOR_END__
0000000000200e38 d __DTOR_LIST__
00000000000005e0 r __FRAME_END__
0000000000200e48 d __JCR_END__
0000000000200e48 d __JCR_LIST__
0000000000201010 A __bss_start
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000000540 t __do_global_ctors_aux
0000000000000490 t __do_global_dtors_aux
0000000000201008 d __dso_handle
                 w __gmon_start__
0000000000201010 A _edata
0000000000201020 A _end
0000000000000578 T _fini
0000000000000438 T _init
0000000000000470 t call_gmon_start
0000000000201010 b completed.6531
0000000000201018 b dtor_idx.6533
0000000000000510 t frame_dummy

Edit: I have a theory that the .so is being built improperly, as $>nm JavaClient.so doesn’t show the method names in it. Any suggestions on what’s wrong about that cc command?

Okay, SO: I kept at this because nothing seemed right. The method signatures were all matched, nothing should be wrong, eclipse file properties said it was editing the right file, etc etc. I finally catted the JavaClient.c, and it was blank. Apparently eclipse wasn’t ACTUALLY editing the file it said it was. Fixed that up and now everything’s fine.

  • 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-06-08T06:11:01+00:00Added an answer on June 8, 2026 at 6:11 am

    I kept at this because nothing seemed right. The method signatures were all matched, nothing should be wrong, eclipse file properties said it was editing the right file, etc etc. I finally catted the JavaClient.c, and it was blank. Apparently eclipse wasn’t ACTUALLY editing the file it said it was. Fixed that up and now everything’s fine.

    Not sure why Eclipse claimed to be editing a blank file, I checked and rechecked and it wasn’t referencing any links or anything, but if you’re having the same problem as me check it out.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.