EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: JCA using problem, JCA/JNI for Windows
From: "Chu, Chungming Paul" <[email protected]>
To: "Guobao Shen (KEK)" <[email protected]>
Cc: [email protected]
Date: Wed, 28 Nov 2007 22:14:42 -0800
FYI, here are the email exchanges we had in August regarding the JCA/JNI compilation on Windows with VC.  Also, Ernest Williams discovered that even after the JCA/JNI library successfully compiled, we still need to run the VC manifest utility to fix the runtime library loading problem:

C:\epicsExtensions\lib\win32-x86>mt.exe -manifest jca.dll.manifest -outputresource:jca.dll;2

After this step (and, of course, include the path to jca.dll in the %PATH%), the JCA/JNI works fine on both XP and Vista.


Paul

~~~~~~~~~~~~~begin forwarded emails~~~~~
Hi Jeff,

Thanks for the info.

In our case we actually trying to use EPICS R3.14.8.2.
We do need epicsShareFunc, right?

Can you send examples of how to deal with this?

If indeed, I remove epicsShareFunc, like so:
==================================================================
// Be backward compatible, EPICS3.14.9(.2) required.
#if ((EPICS_REVISION >= 14) && (EPICS_MODIFICATION >= 9)) #include <epicsExit.h> #else epicsShareFunc void epicsShareAPI epicsExit(int status); int epicsShareAPI epicsAtThreadExit(
                 void (*epicsExitFunc)(void *arg),void *arg){ return 0; } #endif ==========================================================================




Everything compiles, like so:
==============================================================================
C:\epicsExtensions\src\jca-2.3.1>ant
Buildfile: build.xml

build.core.java:
     [echo] Building core classes
     [echo] Copying ressources
     [echo] Done

-init:

build.core.jni.dirs:

build.core.jni.depend:
     [echo] Building native header files
     [echo] Done

build.core.jni.objs:
     [echo] Building native object files
  [applyex] C:\Program Files\Microsoft Visual Studio 8\VC\bin\cl -nologo -EHsc - c -GR -GL -D__STDC__=0 -Ox -W3 -w44355 -MD -IC:\Program Files\Java\jdk1.6.0_02\j re/../include -IC:\Program Files\Java\jdk1.6.0_02\jre/../include/WIN32 -IC:\epic sBase\R3.14.8.2/include -IC:\epicsBase\R3.14.8.2/include/os/WIN32 -IC:/Program F iles/Microsoft Visual Studio 8/VC/include -IO.win32-x86 -FoC:\epicsExtensions\sr c\jca-2.3.1\O.win32-x86\JNI.obj C:\epicsExtensions\src\jca-2.3.1\src\core\gov\ap
s\jca\jni\JNI.cpp
  [applyex] JNI.cpp
  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(40
2) : warning C4996: 'strncpy' was declared deprecated
  [applyex]         C:/Program Files/Microsoft Visual Studio 8/VC/include\string
.h(156) : see declaration of 'strncpy'
  [applyex]         Message: 'This function or variable may be unsafe. Consider
using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. S ee online help for details.'
  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(40
4) : warning C4996: 'strncat' was declared deprecated
  [applyex]         C:/Program Files/Microsoft Visual Studio 8/VC/include\string
.h(143) : see declaration of 'strncat'
  [applyex]         Message: 'This function or variable may be unsafe. Consider
using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. S ee online help for details.'
  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(40
5) : warning C4996: 'strncat' was declared deprecated
  [applyex]         C:/Program Files/Microsoft Visual Studio 8/VC/include\string
.h(143) : see declaration of 'strncat'
  [applyex]         Message: 'This function or variable may be unsafe. Consider
using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. S ee online help for details.'
  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(60
0) : warning C4996: 'sprintf' was declared deprecated
  [applyex]         C:/Program Files/Microsoft Visual Studio 8/VC/include\stdio.
h(345) : see declaration of 'sprintf'
  [applyex]         Message: 'This function or variable may be unsafe. Consider
using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. S ee online help for details.'
  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(63
1) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(87
8) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(90
0) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(91
9) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(93
9) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(96
0) : warning C4003: not enough actual parameters for macro 'INITIALIZE_CALLBACK'

  [applyex] C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(12
12) : warning C4996: 'strncpy' was declared deprecated
  [applyex]         C:/Program Files/Microsoft Visual Studio 8/VC/include\string
.h(156) : see declaration of 'strncpy'
  [applyex]         Message: 'This function or variable may be unsafe. Consider
using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. S ee online help for details.'
     [echo] Done

build.core.jni.lib:
     [echo] Building native library: jca.dll
  [applyex] C:\Program Files\Microsoft Visual Studio 8\VC\bin\link /nologo /LTCG  /subsystem:windows /dll /incremental:no /opt:ref /release /LIBPATH:C:/Program F iles/Microsoft Visual Studio 8/VC/lib /LIBPATH:C:\epicsBase\R3.14.8.2/lib/win32-
x86 ca.lib Com.lib /out:C:\epicsExtensions\src\jca-2.3.1\O.win32-x86\jca.dll C:\ epicsExtensions\src\jca-2.3.1\O.win32-x86\JNI.obj
  [applyex]    Creating library C:\epicsExtensions\src\jca-2.3.1\O.win32-x86\jca
.lib and object C:\epicsExtensions\src\jca-2.3.1\O.win32-x86\jca.exp
  [applyex] Generating code
  [applyex] Finished generating code
[propertyfile] Updating property file: C:\epicsExtensions\src\jca-2.3.1\O.core\g
ov\aps\jca\JCALibrary.properties
     [echo] Done

build.core.jni:
     [echo] done

build.core:
      [jar] Building jar: C:\epicsExtensions\src\jca-2.3.1\O.core\jca.jar
     [echo] done

build:

BUILD SUCCESSFUL
Total time: 1 second
C:\epicsExtensions\src\jca-2.3.1>
===============================================================================



Thanks,
Ernest


-----Original Message-----
From: Jeff Hill [mailto:[email protected]]
Sent: Thu 8/23/2007 2:49 PM
To: Williams Jr., Ernest L.
Cc: [email protected]
Subject: RE: Trying to build JCA under Windows
 

Ernest,

There is a comment in the top of libCom/misc/shareLib.h that shows how to use the epicsShareFunc macro.

In summary, you have to define epicsExportSharedSymbols before including the header file with epicsShareFunc in it if you are exporting that function, and should not have epicsExportSharedSymbols defined before including the header file if you are importing the functions in that header file. This gets more complicated if you are creating a DLL that imports from other DLLs. I can send examples showing how to deal with that situation as your needs dictate.

Also, you need to use the correct visual c++ build options when creating a DLL or importing from the DLL. The typical build options for clients that import from an EPICS DLL are in the ca ref manual (hopefully they are reasonably up to date).

Looking, very quickly, at this code one might surmise that the epicsShareFunc keyword should simply be removed because there is no intent to export or import these dummy functions (to or from a DLL) when the epics revision is less than R3.14.

===============================================================================
In our case, we are trying to use EPICS R3.14.8.2 ===============================================================================



#if ((EPICS_REVISION >= 14) && (EPICS_MODIFICATION >= 9))

#include <epicsExit.h>

#else

epicsShareFunc void epicsShareAPI epicsExit(int status);

epicsShareFunc int epicsShareAPI epicsAtThreadExit(

void (*epicsExitFunc)(void *arg),void *arg){ return 0; }

#endif

Jeff

-----Original Message-----
From: Williams Jr., Ernest L. [mailto:[email protected]]
Sent: Thursday, August 23, 2007 12:51 AM
To: Williams Jr., Ernest L.
Cc: [email protected]; [email protected]
Subject: RE: Trying to build JCA under Windows

Hi Matej,
 
jca-2.3.1 does compile under EPICS R3.14.9.
 
Jeff any ideas on this one?  Read the reference below from Microsoft.
 
 
Thanks,
Ernest

________________________________

From: Williams Jr., Ernest L.
Sent: Wed 8/22/2007 11:48 PM
To: Williams Jr., Ernest L.
Cc: [email protected]
Subject: Trying to build JCA under Windows



Hi Matej,


 

I am trying to build jca under windows:

build.core.jni.objs:
     [echo] Building native object files
  [applyex] C:\Program Files\Microsoft Visual Studio 8\VC\bin\cl -nologo -EHsc - c -GR -GL -D__STDC__=0 -Ox -W3 -w44355 -MD -IC:\Program Files\Java\jdk1.6.0_02\j re/../include -IC:\Program Files\Java\jdk1.6.0_02\jre/../include/WIN32
-IC:\epic
sBase\R3.14.8.2/include -IC:\epicsBase\R3.14.8.2/include/os/WIN32
-IC:/Program F
iles/Microsoft Visual Studio 8/VC/include -IO.win32-x86 -FoC:\epicsExtensions\sr c\jca-2.3.1\O.win32-x86\JNI.obj C:\epicsExtensions\src\jca-2.3.1\src\core\gov\ap
s\jca\jni\JNI.cpp
  [applyex] JNI.cpp
  [applyex]
C:\epicsExtensions\src\jca-2.3.1\src\core\gov\aps\jca\jni\JNI.cpp(10
0) : error C2491: 'epicsAtThreadExit' : definition of dllimport function not all owed

 

Here is the offending line of code:

========== JNI.cpp ============================


// Be backward compatible, EPICS3.14.9(.2) required.

#if ((EPICS_REVISION >= 14) && (EPICS_MODIFICATION >= 9))

#include <epicsExit.h>

#else

epicsShareFunc void epicsShareAPI epicsExit(int status);

epicsShareFunc int epicsShareAPI epicsAtThreadExit(

void (*epicsExitFunc)(void *arg),void *arg){ return 0; }

#endif

==============================================



 


 


Below is a reference from Microsoft MSDN:

You can only apply the __declspec(dllimport) keyword to declarations. You cannot apply the __declspec(dllimport) keyword to implement functions. The purpose of this keyword is to declare the implementation of a function by a DLL. Similarly, if you apply the __declspec(dllimport) keyword to a data member, you receive the initial data from a DLL. Therefore, you cannot assign a value in your code initially.

You receive the Compiler C2491 error message when you try to compile the following code:
// function definition
void __declspec(dllimport) funcB() {   // error C2491: 'funcB' : definition
of dllimport function not allowed
}

This behavior occurs because you defined the function implementation as dllimport. To avoid this compiler error, do not define the function, but instead declare the function as follows:
// function declaration
void __declspec(dllimport) funcB();    // ok

int main() {
}

Similarly, you receive the Compiler C2491 error message when you try to compile the following code:
//defining data member
extern __declspec(dllimport)  int code = 1; // error C2491: 'code' :
definition of dllimport data not allowed

You receive this error message because you defined the data member as dllimport. To avoid this compiler error, do not define the data member, but instead declare the data member as follows:
// declaring data member
extern __declspec(dllimport)  int code;  // ok

~~~~~~~end forwarded emails~~~~~~~


-----Original Message-----
From: Guobao Shen (KEK) [mailto:[email protected]] 
Sent: Wednesday, November 28, 2007 5:18 PM
To: Chu, Chungming Paul; '???'
Cc: [email protected]
Subject: RE: JCA using problem

Hi Paul,
I think there may have a problem when compiling the JCA/JNI library using MSVC2005.
With my old JCA/JNI library (v2.1.7) compiled using MSVC2003 free toolkit, the code works fine.

With the library compiled by MSVC2005, a message windows is popped up.
which says as following: (The JCALibrary.properties is same.)
	Microsoft Visual C++ Runtime Library
	Runtime Error!
	Program: C:\java\jdk1.5.0_14\bin\java.exe
	R6034
	An application has made an attempt to load the C runtime library incorrectly.
	Please contact the application's support team for more information. 

A tracking message throws from java code is as fllowing:
	Exception in thread "main" java.lang.UnsatisfiedLinkError: 
	C:\Java\epics\jca-2.1.7\O.win32-x86\jca.dll:
	A dynamic link library (DLL) initialization routine failed
	        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
	        at java.lang.ClassLoader.loadLibrary(Unknown Source)
	        at java.lang.Runtime.loadLibrary0(Unknown Source)
	        at java.lang.System.loadLibrary(Unknown Source)
	        at gov.aps.jca.jni.JNI$1.run(JNI.java:100)
	        at java.security.AccessController.doPrivileged(Native
Method)
	        at gov.aps.jca.jni.JNI.init(JNI.java:110)
	        at
gov.aps.jca.jni.JNIContext.initialize(JNIContext.java:109)
	        at
gov.aps.jca.jni.JNIContext._initialize(JNIContext.java:145)
	        at
gov.aps.jca.jni.ThreadSafeContext.createChannel(ThreadSafeContext.java:330)
	        at gov.aps.jca.Context.createChannel(Context.java:113)
	        at test.main(test.java:25)

For the version 2.3.1, a similar error was thrown also.

Guobao


-----Original Message-----
From: Chu, Chungming Paul [mailto:[email protected]]
Sent: 2007年11月29日 2:12 AM
To: Guobao Shen (KEK); ???
Subject: RE: JCA using problem

Yes, I think Guobao is right.  I tested your code on my Windows box and it worked fine (with everything set correctly).  The output looks like this:

CLASS : gov.aps.jca.jni.ThreadSafeContext PREEMPTIVE_CALLBACK : true ADDR_LIST : xxxxxx.sns.ornl.gov AUTO_ADDR_LIST : false CONNECTION_TIMEOUT :
30.0 BEACON_PERIOD : 15.0 REPEATER_PORT : 5065 SERVER_PORT : 5064 MAX_ARRAY_BYTES : 16384
EVENT_DISPATCHER: gov.aps.jca.event.QueuedEventDispatcher@1749757
PRIORITY : 1
gov.aps.jca.TimeoutException: pendIO timed out

Of course, for my ADDR_LIST, I don't have a channel called 'light' and got pendIO timed out error.

I also attach my JCALibrary.properties file from my Windows box (it's set to use JCA/JNI, same as in your example).  If you're using Linux, you need to follow the Linux syntax.

If you need further help, could you send more detailed info about the exception thrown and maybe screen print-out?


Paul

-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Guobao Shen (KEK)
Sent: Tuesday, November 27, 2007 6:32 PM
To: '鲍春雷'; [email protected]
Subject: RE: JCA using problem

Hi Bao,
You need set some environment parameter properly for JCA in JCALibrary.properties file before you start using it.
There is a tutorial under doc directory if you downloaded the source code.
Some some detail explanation can be found in that file about how to setJCALibrary.properties .

BTW: Which OS do you use, Linux, Win/XP, ...?
Do you compile the JCA library from source code by yourself?

Guobao Shen

-----Original Message-----
To: [email protected]
Subject: JCA using problem

                                       Hello,all
	I am using JCA to do some experment.But the first program can not run.The error message is:java.lang.IllegalStateException: Context not initialized.
	My environment:
	JDK 1.5
	JCA 2.3.1
	EPICS 3.14.8

	The program:
import gov.aps.jca.Channel;
import gov.aps.jca.Context;
import gov.aps.jca.JCALibrary;

public class test {
	public static void main(String[] args) {
		 try {
			  JCALibrary jca= JCALibrary.getInstance();
		      Context ctxt=
jca.createContext(JCALibrary.JNI_THREAD_SAFE);
		      ctxt.printInfo();
              Channel ch= ctxt.createChannel("light");
			  ctxt.pendIO(5.0);
		      ch.printInfo();
		     ch.destroy();
		      ctxt.destroy();
		    } catch(Exception ex) {
		      System.err.println(ex);
		    }
	}

}

BaoChunlei
Control Group,IHEP





References:
JCA using problem 鲍春雷
RE: JCA using problem Guobao Shen (KEK)
RE: JCA using problem Guobao Shen (KEK)

Navigate by Date:
Prev: RE: JCA using problem Guobao Shen (KEK)
Next: how to recv data by raw socket under VxWorks 黄松
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: JCA using problem Guobao Shen (KEK)
Next: Re: JCA using problem J. Lewis Muir
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Nov 2011 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·