为什么很难在线找到虚拟的.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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...