我正在尝试在linux中创建一个使用opencv和tesseract与动态链接的程序的共享库
我跟着link 我的代码如下
` using System.Windows.Forms;
using basicObjectLib;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
LoadTreeItems();
}
public void LoadTreeItems()
{
// Dummy Data
// created a DLL Basic Class Object Conatining class definitions of anatomy subanatomy
#region Object
Anatomy an1 = new Anatomy();
an1.AnatomyID = 1;
an1.AnatomyName = "Anatomy1";
Subanatomy san1 = new Subanatomy();
san1.SubAnatomyID = 11;
san1.SubAnatomyName = "subAn1";
an1.SubanatomyList.Add(san1);
Subanatomy san2 = new Subanatomy();
san2.SubAnatomyName = "subAn2";
san2.SubAnatomyID = 2;
an1.SubanatomyList.Add(san2);
Anatomy an2 = new Anatomy();
an2.AnatomyID = 2;
an2.AnatomyName = "Anatomy2";
Subanatomy san21 = new Subanatomy();
san21.SubAnatomyName = "subAn1";
san21.SubAnatomyID = 21;
an2.SubanatomyList.Add(san21);
Subanatomy san22 = new Subanatomy();
san22.SubAnatomyName = "subAn2";
san22.SubAnatomyID = 22;
an2.SubanatomyList.Add(san22);
Anatomy an3 = new Anatomy();
an3.AnatomyID = 3;
an3.AnatomyName = "Anatomy3";
Subanatomy san31 = new Subanatomy();
san31.SubAnatomyName = "subAn1";
san31.SubAnatomyID = 31;
an3.SubanatomyList.Add(san31);
Subanatomy san32 = new Subanatomy();
san32.SubAnatomyName = "subAn2";
san32.SubAnatomyID = 32;
an3.SubanatomyList.Add(san32);
List<Anatomy> anatomyObj = new List<Anatomy>();
anatomyObj.Add(an1);
anatomyObj.Add(an2);
anatomyObj.Add(an3);
#endregion
foreach(Anatomy obj in anatomyObj)
{
TreeNode parentNode = new TreeNode();
parentNode = new TreeNode(obj.AnatomyName);
treeView1.Nodes.Add(parentNode);
foreach(Subanatomy subObj in obj.SubanatomyList)
{
TreeNode childNode = new TreeNode();
childNode = new TreeNode(subObj.SubAnatomyName);
parentNode.Nodes.Add(childNode);
}
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Action == TreeViewAction.ByMouse)
{
// name of treeNode
textBox4.Text = treeView1.SelectedNode.Name.ToString();
// to show the ID
textBox2.Text = "";
}
}
private void button1_Click(object sender, EventArgs e)
{
treeView1.ExpandAll();
}
}
public class WindowsFormApplication
{
public static void main()
{
Form1 _treeviewDemo = new Form1();
}
}
}`
这里Test.cpp是一个简单的文件,如下所示
g++ -c Serial_Key.cpp -fPIC -o cdserial `pkg-config --cflags --libs opencv` -llept -ltesseract
g++ -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 cdserial
ln -sf libctest.so.1.0 libctest.so
ln -sf libctest.so.1.0 libctest.so.1
g++ -c Test.cpp -fPIC -o cprog -lctest `pkg-config --cflags --libs opencv` -llept -ltesseract
以某种方式给出了./cprog的错误 ./cprog:无法执行二进制文件:exec格式错误
我觉得我在第二行做了一些基本错误(g ++ -shared) 请指导
答案 0 :(得分:1)
经过多次头部碾压之后,我在上述问题中发现了几个愚蠢的错误
以下是可能陷入类似问题的其他人的更正流程
首先编译
g ++ -c Serial_Key.cpp -fPIC -o cdserial
通过提及库及其使用soname的路径来创建共享库
g ++ -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 cdserial -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs -lopencv_videoio -llept -ltesseract -L / usr / local / lib
将soname与库链接
ln -sf libctest.so.1.0 libctest.so ln -sf libctest.so.1.0 libctest.so.1
为测试文件编译和创建对象
g ++ Test.cpp -fPIC -o cprog -lctest -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs -lopencv_videoio -llept -ltesseract -L / usr / local / lib
将共享库文件复制到本地lib
cp libctest.so / usr / local / lib cp libctest.so.1 / usr / local / lib cp libctest.so.1.0 / usr / local / lib
确保$ LD_LIBRARY_PATH指向共享库路径
export LD_LIBRARY_PATH = / usr / local / lib
运行
./ cprog