将对象(.o)文件添加到qtcreator项目

 敏捷的敏2502921017 发布于 2023-02-07 10:27

如何将第三方.o和.h文件添加到QtCreator中的Qt C++项目?我想从John The Ripper中添加一些已编译的.o文件到我的probject(忽略它的非跨平台性).作为一个测试,一个小的C程序(在QtCreator之外)编写并将其链接common.oMD5_std.o并且它工作正常; 我可以这样做gcc -o runme common.o MD5_std.o simpleprogram.c,但是使用QtCreator,似乎没有任何效果.我一直得到未定义的引用.

我尝试将其添加到.pro文件中:

LIBS += "$$_PRO_FILE_PWD_/common.o" "$$_PRO_FILE_PWD_/MD5_std.o" 

还有这个:

LIBS += /full/path/to/common.o /full/path/to/MD5_std.o

我还尝试INCLUDEPATH在.pro文件中设置和添加.o文件作为"其他文件"和"源",但无论我做什么,对.o文件中的函数的调用总是会导致未定义的引用.

另外,根据我在互联网上找到的所有建议(这对我们很有用,非常奇怪),我没有找到一种方法将.o文件添加到项目中,以便将它们复制到阴影构建中目录,并从那里链接.我似乎错误地提到了$$_PRO_FILE_PWD_.

BTW:我开始工作的是连接系统库.当我添加-lcryptLIBS,包括unistd.h,我可以调用crypt函数就好了.

1 个回答
  • Based on your comment discussion, you seem to have at least two issues ongoing:

    1) You need to use the OBJECTS variable in qmake to have the operation you have with the -o argument of gcc. Here you can find the documentation of it:

    OBJECTS

    This variable is automatically populated from the SOURCES variable. The extension of each source file is replaced by .o (Unix) or .obj (Win32). You can add objects to the list.

    Based on this, you would be writing something like this:

    OBJECTS += common.o MD5_std.o
    

    Note that you will also need to use "extern C" linkage specification to avoid the name mangling. That is necessary to be able to link when using your third-party object coming from C code and such compilation. You would need to be writing this for your corresponding C functions:

    extern "C"
    {
        ...
    }
    

    2023-02-07 10:29 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有