如何解决为什么很难在线找到虚拟的.so文件?
我需要一个虚拟.so文件才能在android中调用它的功能。虚拟.so文件可以是进行加,减等操作的任何内容。 在网上搜索时,我发现的是“什么是.so文件?”,“如何在Android中集成.so文件”。任何人都可以共享一个虚拟的.so文件进行添加吗?
解决方法
这是我的第一个共享库,很容易做到。我已经申请了this toutorial。
这是我的代码:
lib.h
#pragma once
int sum(const int a,const int b);
lib.cpp
#include "lib.h"
int sum(const int a,const int b)
{
return a+b;
}
main.cpp
#include "lib.h"
#include <iostream>
int main()
{
std::cout << sum(10,20) << std::endl;
return 0;
}
并使用theese命令创建了一个:
# generating simple library
c++ -c -Wall -Werror -fPIC lib.cpp
# making it shared
c++ -shared -o libsum.so lib.o
现在您将拥有共享库,为了使该程序正常工作,我必须执行2个附加命令:
# create executable
g++ -L. main.cpp -l:libsum.so -o main
# if you try to run this command it will fail
./main
# so i've set ld path,but in the link above there are alternative solutions to that
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
# now it should work,in my case output is: 30
./main
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。