S.R*_*S.R 0 c++ gcc compiler-errors g++ cross-compiling
我有一个奇怪的问题.我可以编译我的代码,arm但不能x86使用gcc v 6.3(和其他也).这是一个导致问题的示例代码.
#include <stdint.h>
#include <cstdio>
#include <unistd.h>
#include <csignal>
volatile bool $run = true;
static void quitHandler(int __attribute__((unused)) signum)
{
$run = false;
}
void setupQuitHandler()
{
struct sigaction action;
action.sa_handler = quitHandler;
action.sa_flags = SA_RESETHAND;
if (sigemptyset(&action.sa_mask) < 0) printf("[SetupQuit] sigemptyset");
if (sigaction(SIGINT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGINT");
if (sigaction(SIGQUIT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGQUIT");
if (sigaction(SIGTERM, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGTERM");
if (sigaction(SIGABRT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGABRT");
}
int main(int argc, char **argv) {
setupQuitHandler();
while($run)
{
sleep(1);
printf("Do nothing! \n");
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个使用gcc 的在线示例
这会导致汇编错误:
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.cpp"
/tmp/ccEUYGVm.s: Assembler messages:
/tmp/ccEUYGVm.s:19: Error: junk `(%rip)' after expression
/tmp/ccEUYGVm.s:19: Error: unsupported instruction `mov'
/tmp/ccEUYGVm.s:137: Error: junk `(%rip)' after expression
/tmp/ccEUYGVm.s:137: Error: operand type mismatch for `movzb'
make: *** [subdir.mk:26: main.o] B??d 1
Run Code Online (Sandbox Code Playgroud)
更奇怪的是我可以用clang编译它.这里在线示例
我用-O0 -O2和-03参数试过gcc版本4.8,5.x,6.3(x-我不记得了).
如果我删除#include <csignals>也尝试过(<signal.h>)和所有家属没有问题.但抓住'INT'信号很好.
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |