NDK two-libs例子编译时遇到的问题

jiangpingzhan 2011-01-20 10:55:45
1. 把second.c 文件扩展名改成second.cpp

2. 改进代码

/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "first.h"
#include <jni.h>
#include<stdlib.h>
jint
Java_com_example_twolibs_TwoLibs_add( JNIEnv* env,
jobject obj,
jint x,
jint y )
{
return first(x, y);
}


编译时出现


Administrator@PC2010111818iqp /cygdrive/d/android-ndk-r4/samples/two-libs
$ $NDK_ROOT/ndk-build
Compile++ thumb: twolib-second <= /cygdrive/d/android-ndk-r4/samples/two-libs/jn
i/second.cpp
SharedLibrary : libtwolib-second.so
/cygdrive/d/android-ndk-r4/samples/two-libs/bin/ndk/local/armeabi/objs/twolib-se
cond/second.o: In function `Java_com_example_twolibs_TwoLibs_add(_JNIEnv*, _jobj
ect*, int, int)':
/cygdrive/d/android-ndk-r4/samples/two-libs/jni/second.cpp:26: undefined referen
ce to `first(int, int)'
collect2: ld returned 1 exit status
make: *** [/cygdrive/d/android-ndk-r4/samples/two-libs/bin/ndk/local/armeabi/lib
twolib-second.so] Error 1

Administrator@PC2010111818iqp /cygdrive/d/android-ndk-r4/samples/two-libs
$

求教. 这是什么问题. 有没有办法解决 ?
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangpingzhan 2011-01-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 work_acc 的回复:]
undefined reference to `first(int, int)
c++调c的时候出的问题,你懂了么?
[/Quote]

有没有办法解决 ?
work_acc 2011-01-20
  • 打赏
  • 举报
回复
undefined reference to `first(int, int)
c++调c的时候出的问题,你懂了么?
shaojieli 2011-01-20
  • 打赏
  • 举报
回复
如果JNI层改为C++则可以在头文件中加入如下内容:
#ifdef __cplusplus
extern "C"
{
#endif

//函数声明


#ifdef __cplusplus
}
#endif
work_acc 2011-01-20
  • 打赏
  • 举报
回复
一看楼主就是和我一样没有c和c++基础的 3楼正解
freshui 2011-01-20
  • 打赏
  • 举报
回复
extern "C" int first(int, int);

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧