添加对象(.o)文件来qtcreator项目 [英] Adding object (.o) files to qtcreator project

查看:1956
本文介绍了添加对象(.o)文件来qtcreator项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能第三方的.o和.h文件添加到QtCreator Qt的C ++项目?我想从约翰开膛一些编译.o文件添加到我的probject(忽略了非交platformness)。作为一个试验,写了一个小的C程序(QtCreator外),并将其链接对 common.o MD5_std.o 它工作得很好;我可以做的gcc -o邵仁枚common.o MD5_std.o simpleprogram.c ,但与QtCreator,似乎没有任何工作。我不断收到未定义的引用。

How does one add third party .o and .h files to a Qt C++ project in QtCreator? I want to add some compiled .o files from John The Ripper to my probject (ignore the non-cross-platformness of that). As a test, a wrote a small C program (outside QtCreator) and linked it against common.o and MD5_std.o and it worked fine; I can just do gcc -o runme common.o MD5_std.o simpleprogram.c, but with QtCreator, nothing seems to work. I keep getting undefined references.

我尝试添加这给.pro文件:

I tried adding this to the .pro file:

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 并添加.o文件为其他文件和源在pro文件,但是不管我做什么,该调用在.o文件的功能总是导致未定义的引用。

I also tried setting INCLUDEPATH and adding the .o files as 'other files' and 'sources' in the .pro file, but no matter what I do, the calls to the functions in the .o files always result in undefined references.

此外,所有我在互联网上找到的建议(这确实为他们工作,古怪不够),我没有找到一个方法来添加以这样的方式,他们将被复制到.o文件到项目影子build目录,并从那里的联系。我似乎是错误的引用 $$ _ PRO_FILE_PWD _

Additionally, from all the advice I found on the internet (which did work for them, weirdly enough), I didn't find a way to add the .o files to the project in such a way that they are copied to the shadow build directory, and linked from there. I seems wrong to refer to the $$_PRO_FILE_PWD_.

BTW:我没去上班,是连接的系统库。当我添加 -lcrypt LIBS ,包括 unistd.h中,我可以调用crypt函数就好了。

BTW: What I did get to work, is linking a system lib. When I add -lcrypt to LIBS and include unistd.h, I can call the crypt function just fine.

推荐答案

根据您的评论的讨论,你似乎至少有两个问题不断:

Based on your comment discussion, you seem to have at least two issues ongoing:

1),您需要使用变量对象的qmake有你用gcc的 -o 参数的操作。在这里,你可以找到它的文档:

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:

对象

此变量自动从源变量填充。每个源文件的扩展名由的.o(UNIX)或.OBJ的(Win32)取代。您可以将对象添加到列表中。

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

请注意,您还需要使用外部C链接规范,以避免< A HREF =htt​​p://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B>名称重整。这是必要的,以便能够使用从C code和诸如汇编来第三方对象时进行链接。您需要为您的相应的C函数写的:

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"
{
    ...
}

这篇关于添加对象(.o)文件来qtcreator项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆