1

Good day. I'm trying to compile a library for use it in Java. But getting the error "error LNK2019: unresolved external symbol". In c ++ I do not much understand, ask for help. Begin cpp file

//ftrJavaScanAPI.cpp : Defines the entry point for the DLL application.
//
#ifdef _WINDOWS
#pragma warning (disable:4996)
#endif

#include "C:\ftrJavaScanAPI\ftrScanAPI.h"
#include "ftrJavaScanAPI.h"

#ifdef FTR_OS_UNIX
#include <string.h>
#endif

FTRHANDLE hDevice = NULL;
FTRSCAN_IMAGE_SIZE m_ImageSize;
FTR_DWORD m_dwErrCode = 0;

#ifdef _WINDOWS
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    return TRUE;
}
#endif

JNIEXPORT jboolean JNICALL Java_com_Futronic_ScanApiHelper_Scanner_OpenDevice(JNIEnv *env, jobject obj)
{
    hDevice = ftrScanOpenDevice();
    if( hDevice == NULL )
        return JNI_FALSE;
    return JNI_TRUE;
}

Begin .h file:

#include <C:\Program Files\Java\jdk1.7.0_05\include\jni.h>
/* Header for class com_Futronic_ScanApiHelper_Scanner */



#ifndef _Included_com_Futronic_ScanApiHelper_Scanner
#define _Included_com_Futronic_ScanApiHelper_Scanner
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_Futronic_ScanApiHelper_Scanner
 * Method:    OpenDevice
 * Signature: ()Z
 */

JNIEXPORT jboolean JNICALL Java_com_Futronic_ScanApiHelper_Scanner_OpenDevice
  (JNIEnv *, jobject);

Error on Debug

1>ftrJavaScanAPI.obj : error LNK2019: unresolved external symbol ftrScanOpenDevice referenced in function Java_com_Futronic_ScanApiHelper_Scanner_OpenDevice

I understand that it is necessary add code to export some symbols from the DLL so that an export library, but do not know how to do it

  • It looks like the function `ftrScanOpenDevice` isn't being exported properly - you can see [how to do so here](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574423#12574423) – The Forest And The Trees Dec 03 '13 at 15:47

1 Answers1

1

What are you linking into your DLL. Your source files don't contain function 'ftrScanOpenDevice' make sure you add appropriate .LIB file to your build.

Before you introduce the complexities of DLL. Make you can compile and run this simple program:

#include "C:\ftrJavaScanAPI\ftrScanAPI.h"

int main ()
{
   FTRHANDLE hDevice = ftrScanOpenDevice();

}

Make sure you can compile this and produce EXE file. Also, your executable should run without an error. It should not produce any output. If get you errors regarding DLL files not found, make sure you have appropriate DLL files available in your path or in the same directory that contains your EXE file. Also, make sure you have the same DLLs available for your final JNI program.

One more thing, you shouldn't hard code the absolute names for your include files. Use Visual Studio settings to add 'FTRScanAPI' to your include and library paths. So your include directive should be just

    #include "ftrScanAPI.h"
Vlad
  • 9,180
  • 5
  • 48
  • 67
  • This little program generates the same error. ftrJavaScanAPI.obj : error LNK2019: unresolved external symbol ftrScanOpenDevice referenced in function main – user1563372 Dec 04 '13 at 06:15