none
LINK : fatal error LNK1104: cannot open file 'libcpmt.lib'

    Question

  • I am trying to use the Java Native Interface(JNI) to compile and run a simple program. I am following the steps found here: http://java.sun.com/docs/books/jni/html/start.html#27008

     

    I have gone through the first several steps successfully.

    1) I created a Java program with appropriate native methods

     

    •    public class HelloJNI
    • {
    •       private native void print();
    •       public static void main(String[] args)
    •       {
    •          new HelloJNI().print();
    •       }
    •       static
    •       {
    •          System.loadLibrary("HelloJNI");
    •       }
    •    }

    2) I called javah -jni on my class file to create the C style header file

    3) I wrote the implementation specified by the header in C++

     

    • #include <jni.h>
    • #include <iostream>
    • #include "HelloJNI.h"
    • using namespace std;
    • JNIEXPORT void JNICALL 
    • Java_HelloJNI_print(JNIEnv *env, jobject obj)
    • {
    •   cout << "Hello JNI!" << endl;
    •   return;
    • }
    4) Now I am at the step when I need to compile the C++ file and generate the .dll
        I initially tried running this command: 
       cl
          -I"C:\Program Files\Java\jdk1.7.0\include"
    -I"C:\Program Files\Java\jdk1.7.0\include\win32" -MD -LD HelloJNI.cpp
    -FeHelloJNI.dll
       but when I ran this I got an error:
      C:\Program Files\Java\jdk1.7.0\include\jni.h(39) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
     
    So the command I am trying to run now is:
    cl
    -I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE"
    -I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include"
    -I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/lib"
    -I"c:/Program Files/Java/jdk1.7.0/include" -I"c:/Program Files/Java/jdk1.7.0/include/win32"
    -LD HelloJNI.cpp -FeHelloJNI.dll
    And When I run this I get:
    LINK : fatal error LNK1104: cannot open file 'libcpmt.lib'
    Which doesn't make any sense to me beucause 'libcpmt.lib' is on my PATH variable and should be including in the cl command because I point -I to the directory it is in.
    Has anyone encountered this issue? 
    Any help would be great.
    Thanks

     

     


    • Edited by Hunter McMillen Thursday, September 22, 2011 10:05 PM formatting
    Thursday, September 22, 2011 10:04 PM

Answers

  • PATH is not used by CL.

    /I let you specify a directory for header include files, not library files.

    Open a dos box and run vcvars32.bat (in vc/bin), it will set default environment values (INCLUDE, LIB) for default values for C++ so you won't have to specify them on command line.

     

    Friday, September 23, 2011 1:19 AM

All replies

  • PATH is not used by CL.

    /I let you specify a directory for header include files, not library files.

    Open a dos box and run vcvars32.bat (in vc/bin), it will set default environment values (INCLUDE, LIB) for default values for C++ so you won't have to specify them on command line.

     

    Friday, September 23, 2011 1:19 AM
  • Thanks for your response, I didn't know that about -I I thought it was for any sort of file I wanted to import. 

     

    I ran vcvars32.bat from the dos prompt like you said and it created HelloJNI.dll which is awesome thank you!!

     

    But when I try to run my Java program with java HelloJNI 

    I get this message:

     

    • Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\java\JNI\HelloJNI.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
    •         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 HelloJNI.<clinit>(HelloJNI.java:12)

     

    Is there some other option to set to say I want to compile under a 64-bit system? I run Windows 7 btw.

     

    Thanks.

    Also I tried running vcvarsall.bat instead before the dll creation and received the same error


    Friday, September 23, 2011 1:29 AM
  • in vc/bin/amd64, there is a vcvars64.bat file which set up environment for 64 bits. There is also cl.exe in this directory, which should be the amd 64 bits version. But I have never compiled in 64 bits using the command line, so I'm not sure. Maybe running vcvars64.bat instead of vcvars32.bat is all you have to do.

    I don't use cl command line very often. Visual Studio has a "configuration manager", where I can create one or more targets (x86, x64, arm...)  for my projects. And I do that with my mouse ! :D

     

    Friday, September 23, 2011 1:48 AM
  • Weird I dont seem to have an amd64 folder inside of vc/bin. I will have to look into that, thank you for all of your help.

     

    Friday, September 23, 2011 2:04 AM