16
Авг
2017

undefined reference to “ с++

Продолжая изучать тему нативных библиотек Java при попытке вызвать метод с++ из с получаю ошибку сборки:

CMakeFiles\Cpart.dir/objects.a(tr1nks_NativeLibraryWrapper.c.obj): In 
function `Java_tr1nks_NativeLibraryWrapper_voidMethod': D:/WORKSPACE/Intellij_Idea/NoAsm/NativeLibraryTest+HowTo/Cpart/tr1nks_NativeLibraryWrapper.c:5: undefined reference to `voidMethod'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [libCpart.dll] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Cpart.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Cpart.dir/rule] Error 2
CMakeFiles\Cpart.dir\build.make:123: recipe for target 'libCpart.dll' failed
mingw32-make.exe: *** [Cpart] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Cpart.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Cpart.dir/rule' failed
Makefile:117: recipe for target 'Cpart' failed

С с и с++ настолько не силен (проходили первые пол курса университета и такое соотв. не изучали) В чем моя ошибка, можно пожалуйста более-менее подробно ?

файлы :

tr1nks_NativeLibraryWrapper.h:

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

#ifndef _Included_tr1nks_NativeLibraryWrapper
#define _Included_tr1nks_NativeLibraryWrapper    
#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL Java_tr1nks_NativeLibraryWrapper_voidMethod(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

tr1nks_NativeLibraryWrapper.c:

#include "tr1nks_NativeLibraryWrapper.h"
#include "NativeLibraryImplementation.h"

JNIEXPORT void JNICALL Java_tr1nks_NativeLibraryWrapper_voidMethod(JNIEnv *env, jobject obj) {
voidMethod(env,obj);

}

NativeLibraryImplementation.h :

#ifndef CPART_NATIVELIBRARYIMPLEMENTATION_H
#define CPART_NATIVELIBRARYIMPLEMENTATION_H

#include <jni.h>

void voidMethod(JNIEnv *, jobject);

#endif //CPART_NATIVELIBRARYIMPLEMENTATION_H

NativeLibraryImplementation.cpp :

#include "NativeLibraryImplementation.h"
#include <iostream>

using namespace std;

void voidMethod(JNIEnv *env, jobject obj) {
cout << "native void method output\n";
}

CMakeLists.txt :

cmake_minimum_required(VERSION 3.8)
project(Cpart)

set(CMAKE_CXX_STANDARD 17)

include_directories("$ENV{JAVA_HOME}/include" "$ENV{JAVA_HOME}/include/win32")

set(SOURCE_FILES tr1nks_NativeLibraryWrapper.h tr1nks_NativeLibraryWrapper.c NativeLibraryImplementation.h NativeLibraryImplementation.cpp)

add_library(Cpart SHARED ${SOURCE_FILES})

Источник: https://ru.stackoverflow.com/questions/706574/undefined-reference-to-%D1%81

Share

Тебе может это понравится...