热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法在C++项目中找到程序入口点-Can'tfindprogramentrypointinaC++project

IhaveaC++projectinUbuntu12.04.Toruntheprojectthemakefilerequiresthefollowingfiles:

I have a C++ project in Ubuntu 12.04. To run the project the make file requires the following files:

我在Ubuntu 12.04中有一个C ++项目。要运行项目,make文件需要以下文件:

1-All the .cpp files

1 - 所有.cpp文件

2-All the .h files

2 - 所有.h文件

3-Three shared libraries.

3-Three共享库。

The project is fully functionall and performs according to the specifications. All the required .cpp files and .h files are available. The problem is that there is no main() function in any of the source files and the program entry point resides in one of the three shared libraries. My job is to find out the program execution pipeline and without having any main file I am not able to do that. I can't run the project in any IDE (i.e: eclipse) because there is no main function available.

该项目功能齐全,可根据规格执行。所有必需的.cpp文件和.h文件都可用。问题是任何源文件中都没有main()函数,程序入口点位于三个共享库之一。我的工作是找出程序执行管道,没有任何主文件,我无法做到这一点。我无法在任何IDE中运行该项目(即:eclipse),因为没有可用的主要功能。

Question: Can you please tell me how to find the program entry point?

问:你能告诉我如何找到程序入口点吗?

P.S: I will be glad to provide any kind of information or material you may need to solve my problem.

P.S:我很乐意提供您解决问题所需的任何信息或材料。

Edit: The CMakeLists.txt file available here.

编辑:此处提供的CMakeLists.txt文件。

Edit 2: The build.sh file available here.

编辑2:此处提供build.sh文件。

3 个解决方案

#1


4  

To find enty point look into each shared object with:

通过以下方式查找每个共享对象的内容:

nm $library | egrep "T main$"

Library with main() will output something like

带main()的库将输出类似的内容

090d8ab0 T main

Very usefull way to visualize execution tree is to run:

可视化执行树的非常有用的方法是运行:

valgrind --tool=callgrind ./my_executable -arg -arg ....

(you can abort execution early with Ctrl+C)

(您可以使用Ctrl + C提前中止执行)

This will output callgrind. file. To visualize it run kcachegrind callgrind..

这将输出callgrind。 文件。要想象它运行kcachegrind callgrind。


You will need valgrind:

你需要valgrind:

sudo apt-get install valgrind

and kcachegrind

sudo apt-get install kcachegrind

#2


0  

Build it with the debug option -g and step into the program with a debugger like gdb (or cgdb or ddd). You'll need any appropriate debug libraries libraries though.

使用调试选项-g构建它,并使用调试器(如gdb(或cgdb或ddd))进入程序。但是,您需要任何适当的调试库库。

Short of that, play with the code a bit. Try putting printf or cout statements that print internal variables in any functions that look important, and see what the program status is and how frequently they get called. If main is hidden in a library, there's probably another function somewhere that behaves like main for the purposes of the API provided by whatever library has the real main.

没错,请稍微玩一下代码。尝试将printf或cout语句放在任何看起来很重要的函数中打印内部变量,并查看程序状态以及调用它们的频率。如果main隐藏在库中,那么可能存在另一个函数,其行为类似于main,用于由任何库具有真正的main提供的API。

What's the API documentation for your libraries? (is this a school project?). It sounds odd to have a hidden main and not say anything about it.

您的库的API文档是什么? (这是一个学校项目吗?)。拥有一个隐藏的主体并且没有任何关于它的说法听起来很奇怪。

#3


0  

In case you use a build system (CMake, SCons, ...) it is highly possible that the build system is also generating some files, and one of them might be containing the main() method. We use this methodology when we generate the main function in order to instantiate classes for libraries that were specifically selected in CMake-gui.

如果您使用构建系统(CMake,SCons,...),构建系统很可能也生成一些文件,其中一个可能包含main()方法。当我们生成main函数时,我们使用这种方法来实例化在CMake-gui中专门选择的库的类。

And again, it is possible that the build system deletes the generated files due to some obscure policy the original developers thought of but didn't tell you. So search through your build system files, see what is actually happening there.

同样,构建系统可能会删除生成的文件,因为原始开发人员想到的一些模糊的策略却没有告诉你。因此,搜索构建系统文件,查看实际发生的情况。

Edit

So, after seeing you CMakeLists.txt:

所以,在看到你CMakeLists.txt之后:

check ${DIR_EXT}/covis/src/ci.cpp where DIR_EXT is SET( DIR_EXT "../ext/" CACHE PATH "Folder holding external libraries" )

检查$ {DIR_EXT} /covis/src/ci.cpp其中DIR_EXT是SET(DIR_EXT“../ext/”CACHE PATH“文件夹持有外部库”)

See what's in there and let us know :)

看看那里有什么,让我们知道:)

Edit2

After seeing build.sh (execute steps in order):

看到build.sh后(按顺序执行步骤):

1. change

`cmake -D COMPILE_BINARY=ON ..` 

to

`cmake -D COMPILE_BINARY=ON -DCMAKE_BUILD_TYPE=Debug ..`

and add the same -DCMAKE_BUILD_TYPE=Debug to the other cmake command too.

并将相同的-DCMAKE_BUILD_TYPE = Debug添加到另一个cmake命令中。

This will build your library and executable in debug mode.

这将在调试模式下构建您的库和可执行文件。

2. Now, in one of the c++ source files you have access to and you are sure will be called (the earlier the function will be calle the better), add:

2.现在,在您可以访问的一个c ++源文件中,您确定将被调用(函数越早越好),添加:

asm("int $0x03");

This will create a breakpoint in your application.

这将在您的应用程序中创建一个断点。

(If you do not want to use this, see below).

(如果您不想使用此功能,请参阅下文)。

3. Build your application.

3.构建您的应用程序。

4. Run it via a debugger in terminal:

4.通过终端中的调试器运行它:

gdb ./myapplication 

(this will give you a gdb prompt)

(这会给你一个gdb提示)

(if you did not add the asm breakpoint from above, type in the gdb prompt: break filename.cpp:linenumber or break methodname to add a gdb breakpoint).

(如果你没有从上面添加asm断点,请输入gdb提示符:break filename.cpp:linenumber或break methodname以添加gdb断点)。

run 

Now your application should stop in your function when it is executed. You are still in the gdb prompt, so type:

现在,您的应用程序应在执行时停止在您的函数中。您仍然在gdb提示符中,因此键入:

bt 

This will print out the backtrace of your application. Somewhere you should see a main function, together with filename and linenumber.

这将打印出您的应用程序的回溯。在某个地方,您应该看到一个主要功能,以及文件名和亚麻布。

However, that setnames.sh looks interesting, see if it does not do anything funny :)

但是,setnames.sh看起来很有趣,看看它是不是做了什么搞笑:)


推荐阅读
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 本文讨论了如何使用GStreamer来删除H264格式视频文件中的中间部分,而不需要进行重编码。作者提出了使用gst_element_seek(...)函数来实现这个目标的思路,并提到遇到了一个解决不了的BUG。文章还列举了8个解决方案,希望能够得到更好的思路。 ... [详细]
  • 如何解决《python中的功能管道,如R'sdplyr中的%>%》经验,为你挑选了9个好方法。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 怀疑是每次都在新建文件,具体代码如下 ... [详细]
  • 基于dlib的人脸68特征点提取(眨眼张嘴检测)python版本
    文章目录引言开发环境和库流程设计张嘴和闭眼的检测引言(1)利用Dlib官方训练好的模型“shape_predictor_68_face_landmarks.dat”进行68个点标定 ... [详细]
  • Python中的PyInputPlus模块原文:https ... [详细]
  • Jenkins 2.0
    [TOC]Jenkins2.0支持BlueOcean界面,如下:image.png2.0的三个特点:PipelineasCode:全新的开箱体验:即变好看了。1.x兼容性Pipel ... [详细]
  • 放假这段时间好好的思考了一下关于Scrapy的一些常用操作,主要解决了三个问题:1.如何连续爬取2.数据输出方式3.数据库链接一,如何连续爬取:思 ... [详细]
author-avatar
邻居小明
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有