1 Reply Latest reply: Mar 18, 2009 3:17 PM by 843810 RSS

    Using boost asio in JVMTI?

    843810
      Hi,

      This is probably a long shot, but I'm going to try and ask anyway. I've got an
      application in which I have to do some profiling of Java software. The profiler
      has to communicate with a client via sockets (may sound strange, but that's the
      way it is). At any rate, I wanted to make the code as portable as possible, so I
      started trying to use the boost asio libraries. Here's the thing, I can get my
      profiler to start just fine as long as I don't #include <boost/asio.hpp>. As
      soon as I do that, the agent won't load. Here is a very simple example program:
      //standard header files.
      #include "stdafx.h"
      #include <iostream>
      #include <sys/types.h>
      //#include <boost/asio.hpp>
      
      #include "jni.h"
      #include "jvmti.h"
      
      
      /** all callbacks must be extern C */
      extern "C" {
      
      JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
           std::cout << "Agent loaded..." << std::endl;
      
           return JNI_OK;
      }
      JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
           std::cout << "Agent unloaded..." << std::endl;
      }
      
      }
      The above works fine, but if I uncomment the #include <boost/asio.hpp>, it dies
      with the standard (uninformative) JVMTI error. Here is my linking command (using
      mingw on windows XP).

      g++ -LC:\Program Files\Java\jdk1.6.0_03\lib -LE:\boost\boost_1_38_0\stage\lib
      -static-libgcc -shared -Wl,-soname=Tester,--kill-at -oTester.dll src\stdafx.o
      src\dllmain.o src\communication\Command.o src\Tester.o -lws2_32
      -lboost_date_time-mgw34-mt -lboost_system-mgw34-mt -lboost_thread-mgw34-mt
      -lboost_iostreams-mgw34-mt -lboost_filesystem-mgw34-mt
      cmd /c copy Tester.dll ..\Tester.dll

      Any ideas? Am I missing a library? Thanks.

      Del
        • 1. Re: Using boost asio in JVMTI?
          843810
          I discovered the problem: I'm linking with g++ from mingw on windows. mingw, for some reason, builds the libraries as .lib files where g++ expects .a files. So, it wasn't linking properly. I had to rename all of my .libs to .as