c - Cairo 创建 png 文件时使用 clang LLVM 编译器的非法硬件指令
问题描述
我试图执行一个 C 程序。它已经正确编译,但是当我执行输出二进制文件时,它显示:
[16] 70041 illegal hardware instruction ./create
所以,我添加-g
选项看起来像这样:
cc create.c $(pkg-config --cflags --libs cairo) -g -o create
和 C 代码:
#include <cairo.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
cairo_surface_t *surface;
cairo_t *cr;
int j=0;
char seq[5];
for(int i=0; i<=360; i+=4){
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 800, 600);
cr = cairo_create(surface);
cairo_set_line_width (cr, 6.0);
cairo_arc( cr, 800/2, 600/2, (600/2)-50, 0, 2*M_PI );
cairo_stroke (cr);
cairo_set_source_rgb( cr, 0.2, 0.2, i/360 );
cairo_arc( cr, 800/2, 600/2, (600/2)-60, 0, i*(M_PI/180.0) );
cairo_stroke(cr);
j++;
if( j<10 ){ sprintf(seq, "%s%d%d", "seq", 0, j); } else { sprintf(seq, "%s%d", "seq", j); }
cairo_surface_write_to_png(surface, seq);
cairo_surface_destroy(surface);
}
cairo_destroy(cr);
return 0;
}
上面代码的目的是创建一个png
s图片序列。但是输出没有任何警告。
我包括lldb
输出:
(lldb) target create "create"
Current executable set to '/Users/rikky/Documents/C/Cairo/FirstDraw/create' (x86_64).
(lldb) l
7 int main(void){
8 cairo_surface_t *surface;
9 cairo_t *cr;
10 int j=0;
11 char seq[5];
12
13 for(int i=0; i<=360; i+=4){
14 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 800, 600);
15 cr = cairo_create(surface);
16 cairo_set_line_width (cr, 6.0);
(lldb) run
Process 70245 launched: '/Users/rikky/Documents/C/Cairo/FirstDraw/create' (x86_64)
Process 70245 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x00007fff6e80ffca libsystem_c.dylib`__chk_fail_overflow.cold.1 + 16
libsystem_c.dylib`__chk_fail_overflow.cold.1:
-> 0x7fff6e80ffca <+16>: ud2
libsystem_c.dylib`__chk_fail_overlap.cold.1:
0x7fff6e80ffcc <+0>: pushq %rbp
0x7fff6e80ffcd <+1>: movq %rsp, %rbp
0x7fff6e80ffd0 <+4>: leaq 0x6e41(%rip), %rdi ; "detected source and destination buffer overlap"
Target 0: (create) stopped.
我没看懂EXC_I386_INVOP
代码。有什么办法可以解决吗?
Clang 版本:
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
解决方案
推荐阅读
- css - v-btn 在鼠标悬停/悬停时闪烁/闪烁
- java - Scala 使用 intellijidea 在 Java 11 上构建错误
- android - 无法使用 RecyclerView 的 onClickeListener 为简单的单例分配新值
- java - 单击listview上的项目以获取片段后如何刷新数据
- java - Java 选项计数器
- c# - 如何在 ZK4500 指纹扫描仪中将手指数据保存到数据库并使用 c# 匹配手指?
- sql-server - 与另一个表的日期列相比,根据其日期列更新表
- ruby-on-rails - 实施acts_as_commentable时出错:未初始化的常量 Discussion::Comment
- node.js - Azure AD B2C (NodeJS):使用有效令牌的请求出现未经授权的 401 错误
- java - 无法从本地系统帐户检索进程信息