什么时候:
- 我更改了类结构(添加/删除方法或更改它们的签名);
- 此类继承自
QObject; - 里面是用
Q_OBJECT的,
当我进一步编译时,我得到一个错误:
未定义对“类名的 vtable”的引用
这是什么原因以及如何解决?
什么时候:
QObject;Q_OBJECT的,当我进一步编译时,我得到一个错误:
未定义对“类名的 vtable”的引用
这是什么原因以及如何解决?
我实现了我的重载operator==以将我std::pair<...>的与std::string. 但由于某种原因,编译器找不到这个重载。它可以与什么连接?
重现错误的代码:
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
typedef std::pair<std::string, int> RegPair;
bool operator==(const RegPair& lhs, const std::string& rhs)
{
return lhs.first == rhs;
}
int main()
{
std::vector<RegPair> sequence;
std::string foo("foo");
std::find(sequence.begin(), sequence.end(), foo);
}
错误文字:
GNU GCC:
错误:在 '__first. __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* with _Iterator = std::pair, std::allocator >, int>*, _Container = std::vector, std::allocator >, int>, std::分配器,std::allocator >, int> > > == __val'
铛:
错误:二进制表达式的操作数无效('std::pair, int>' 和 'std::basic_string const')
有一个对象在销毁之前必须等待某个异步事件。如何延缓这种破坏,使阶级成员即使在之后继续存在Set foo = Nothing?
示例:假设这是一个使用 Waveform Audio API 的播放器。在释放缓冲区之前,它必须等待窗口消息MM_WOM_DONE。
在清空引用之前显式调用某些函数是不可接受的 - 我想避免由于类用户的健忘而导致资源泄漏。
我有一个包含.gitignore以下内容的文件:
*
!/.gitignore
!CMakeLists.txt
!*.cpp
!*.hpp
根据这个想法,它应该允许添加:
.gitignore在存储库的根目录,CMakeLists.txt夹和子文件夹中的文件,.cpp以及.hpp任何文件夹和子文件夹中,并禁止其他一切。
但是,许可规则只影响位于存储库根目录的文件。这在原则上是合乎逻辑的:
规则格式
- 可选前缀“!”,反转规则的动作;任何匹配它并被上述规则排除的文件都将被包括回来。如果文件位于已排除的文件夹中,则无法包含该文件。Git 不会出于优化目的查看排除文件夹的内容,因此规则不适用于它们的内容。
图案格式
- 一个可选的前缀“!” 这否定了模式;先前模式排除的任何匹配文件将再次包含在内。如果排除了该文件的父目录,则无法重新包含该文件。出于性能原因,Git 不会列出排除的目录,因此包含文件的任何模式都无效,无论它们在何处定义。
也就是说,排除所有子文件夹的第一条规则实际上使下面的允许规则无效。
问题:我应该如何正确地只包含具有特定扩展名的文件,而不考虑它们的位置和嵌套级别?
我听说存在大量的工作流(开发流程)—— git flow、github flow、gitlab flow。
它们的性质是什么,它们有何不同?毕竟,分支在所有三种情况下都会发生。
具有以下值CFLAGS:
-Wall -Werror -Wextra -pedantic -std=c99 -O3 -nostartfiles -nodefaultlibs
我的入口点__start(注意-nostartfiles)编译成功并将其放入可执行文件中。
但是,在添加标志时-flto,优化器会抛出入口点本身和仅由它调用的所有函数。此外,进一步链接的执行没有错误和警告,但具有不正确的(随机)入口点。
问题:如何防止删除函数__start?了解为什么链接器在优化期间“忘记”在没有内置入口点的情况下存在对我的入口点的依赖性也很有趣。
GCC 版本:gcc(i686-posix-dwarf-rev1,由 MinGW-W64 项目构建)4.9.2。
源代码(已更正以反映有关 Windows ABI 功能的注释[在原始版本中是注释,但在这里我将其添加到答案中 - 大约 Per.]):
#include <windows.h>
void _start()
{
MessageBox(NULL, TEXT("Hello world."), TEXT(""), MB_OK);
ExitProcess(0);
}
链接器发出的汇编代码(-S):
没有的选项-flto:
Disassembly of section .text:
00401000 <__start>:
401000: 83 ec 1c sub $0x1c,%esp
401003: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp)
40100a: 00
40100b: c7 44 24 08 00 20 40 movl $0x402000,0x8(%esp)
401012: 00
401013: c7 44 24 04 0d 20 40 movl $0x40200d,0x4(%esp)
40101a: 00
40101b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
401022: ff 15 54 40 40 00 call *0x404054
401028: 83 ec 10 sub $0x10,%esp
40102b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
401032: ff 15 4c 40 40 00 call *0x40404c
401038: 90 nop
401039: 90 nop
40103a: 90 nop
40103b: 90 nop
40103c: 90 nop
40103d: 90 nop
40103e: 90 nop
40103f: 90 nop
00401040 <__CTOR_LIST__>:
401040: ff (bad)
401041: ff (bad)
401042: ff (bad)
401043: ff 00 incl (%eax)
401045: 00 00 add %al,(%eax)
...
00401048 <__DTOR_LIST__>:
401048: ff (bad)
401049: ff (bad)
40104a: ff (bad)
40104b: ff 00 incl (%eax)
40104d: 00 00 add %al,(%eax)
选项 c -flto(注意没有_start,但有 API 函数的适配器):
Disassembly of section .text:
00401000 <_ExitProcess@4>:
401000: ff 25 4c 30 40 00 jmp *0x40304c
401006: 90 nop
401007: 90 nop
00401008 <_MessageBoxA@16>:
401008: ff 25 54 30 40 00 jmp *0x403054
40100e: 90 nop
40100f: 90 nop
00401010 <__CTOR_LIST__>:
401010: ff (bad)
401011: ff (bad)
401012: ff (bad)
401013: ff 00 incl (%eax)
401015: 00 00 add %al,(%eax)
...
00401018 <__DTOR_LIST__>:
401018: ff (bad)
401019: ff (bad)
40101a: ff (bad)
40101b: ff 00 incl (%eax)
40101d: 00 00 add %al,(%eax)
这道题翻译的是《Prevent __start entry point from being optimized out》。