gpt4 book ai didi

java - 链接库时找不到符号

转载 作者:行者123 更新时间:2023-11-28 07:07:24 26 4
gpt4 key购买 nike

我正在尝试链接我拥有的 JNI 项目中的库。我遇到了一个奇怪的错误,控制台输出告诉我有一个“找不到 x86 64 体系结构的符号”。我有点不知道可能出了什么问题。还有其他类,但它们太多了,无法放在这里。这是我的代码:

编辑:我将包括整个控制台调试日志。它没有提到哪个符号是有问题的。

编辑 2:我修复了一个有问题的静态变量,但它仍然报错。更新代码以反射(reflect)更改

控制台调试日志:

14:24:05 **** Build of configuration Debug for project HPA* Program ****
make all
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libhpaprogram.o
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name HPAProgram.c++ -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -coverage-file "/Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/jni/libhpaprogram.o" -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -I /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ -stdlib=libstdc++ -fdeprecated-macro -fdebug-compilation-dir "/Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/jni" -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o libhpaprogram.o -x c++ HPAProgram.c++
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
libtool -dynamic -lSystem libhpaprogram.o -o libhpaprogram.dylib
ld: warning: -macosx_version_min not specified, assuming 10.8
Undefined symbols for architecture x86_64:
"__Z11create_dcdtv", referenced from:
_Java_HPAProgram_sayHello in libhpaprogram.o
ld: symbol(s) not found for architecture x86_64
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: internal link edit command failed
make: *** [libhpaprogram.dylib] Error 1

14:24:05 Build Finished (took 162ms)

HPAProgram.c++

#include <stdio.h>
#include "HPAProgram.h"
#include "DCDTWrapper.h"

extern void create_dcdt();
JNIEXPORT void JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) {
printf("Hello World!\n");
create_dcdt();
}

DCDTWrapper.h

# include "DCDTsrc/se_dcdt.h"
# include "DCDTsrc/gs_polygon.h"
# include <stdlib.h>
void create_dcdt ();

DCDTWrapper.c++

# define END 12345.6
# define FIRST_EXAMPLE Example1
//# include "DCDTsrc/se_dcdt.h"
//# include "DCDTsrc/gs_polygon.h"
//# include <stdlib.h>
# include "DCDTWrapper.h"

static double Example1[] =
{ -10, -10, 10, -10, 10, 10, -10, 10, END,
1, 1, 7, 3, 3, 8, END,
END };

static const double* CurExample = FIRST_EXAMPLE;
static SeDcdt *TheDcdt;
static GsPolygon CurPath;
static GsPolygon CurChannel;
static float CurX1=0, CurY1=0, CurX2=0, CurY2=0;
static int CurSelection=0; // -2,-1: moving point, >0: moving polygon


void create_dcdt ()
{
const double* data = CurExample;
GsPolygon pol;

// domain:
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt->init ( pol, 0.00001f );

while ( *++data!=END )
{ pol.size(0);
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt->insert_polygon ( pol );
}
}

生成文件:

# Define a variable for classpath
CLASS_PATH = ../bin

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all: libhpaprogram.dylib

# $@ matches the target, $< matches the first dependancy
libhpaprogram.dylib:
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libhpaprogram.o
libtool -dynamic -lSystem libhpaprogram.o -o libhpaprogram.dylib

HPAProgram.h : HPAProgram.class
javah -classpath $(CLASS_PATH) $*

clean:
rm HPAProgram.h libhpaprogram.o libhpaprogram.dylib

最佳答案

这是你的问题:

static void create_dcdt ();

当您在头文件中将全局对象声明为静态时,包含它的每个翻译单元(即:cpp 文件)都将想要创建该对象的自己的版本。

您可能想用 extern 限定 create_dcdt():

extern void create_dcdt();

然后在文件 DCDTWrapper.c++ 中删除静态限定符。

这将告诉编译器允许 undefined object 的所有版本在链接时被解析为存在于一个 cpp 文件中的单个版本。

(extern 关键字可能是可选的,但您肯定不想在这里使用 static)

关于java - 链接库时找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21587202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com