최적화하지 않고 C 코드를 컴파일하고 싶습니다. 그러나 컴파일 명령에 -O0 옵션을 추가하면 함수의 "다중 정의"오류가 많이 발생합니다. 쓰지도 않았다! 내가 여기 GCC : 이상한 오류 -O0, 없음 없음
내 코드의 ... 여기보고 싶어하지만, 멍청한 놈으로 내가 그냥 무엇을 알아낼 수 없습니다 분명 뭔가가있을 것 같아요 :#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <wiringPi.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <semaphore.h>
#include <unistd.h>
#include <sched.h>
#include <time.h>
#define N 1800
unsigned long int tsec, tnsec;
int main(void)
{
int err, i;
printf("started\n");
struct timespec tps, tpe, req, rem;
req.tv_nsec = 400000;
req.tv_sec = 0;
struct sched_param param;
param.sched_priority = 99;
err = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
if (err != 0)
printf("sched_setscheduler error");
err = sched_getparam(getpid(), ¶m);
if (err != 0)
printf("sched_getparam error");
printf("priority = %i\n", param.sched_priority);
int policy = sched_getscheduler(getpid());
printf("policy = %i\n", policy);
sleep(1);
clock_gettime(CLOCK_REALTIME, &tps);
#include "noppynop2.c"
#include "noppynop2.c"
#include "noppynop2.c"
#include "noppynop2.c"
#include "noppynop2.c"
#include "noppynop2.c"
clock_gettime(CLOCK_REALTIME, &tpe);
tnsec = tpe.tv_nsec - tps.tv_nsec;
tsec = tpe.tv_sec - tps.tv_sec;
printf("time = %lu sec %lu nsec\n", tsec, tnsec);
printf("finished\n");
return 0;
}
가 일 요약하면, 그것은에 bruteforce 시도이다 실시간 커널의 리눅스에 지연을 일으킨다. "noppynop2.c"에는 500 배 asm ("nop")이 포함됩니다. 나는 이것이 여기의 문제라고 생각하지 않지만 그것은 상황이다. 코드는 대부분 테스트 일 뿐이므로 컴파일러가 예측할 수없는 양의 "nops"를 제거하는 경향이 있기 때문에 모든 최적화 작업을 제거하고 싶습니다. 이는 내가하려는 작업과 정반대입니다.
[email protected] ~/Desktop/Projects/test_timemeasure_sched $ gcc -Wall -o test_time_measure_sched main.c -lwiringPi -lpthread -lrt
main.c: In function ‘main’:
main.c:22:33: warning: unused variable ‘rem’ [-Wunused-variable]
main.c:22:28: warning: variable ‘req’ set but not used [-Wunused-but-set-variable]
main.c:19:11: warning: unused variable ‘i’ [-Wunused-variable]
을하지만이 -O0을 추가 할 때 여기에 내가 무엇을 얻을 : ...
나는 -O0 옵션없이 컴파일, 다 잘 간다
[email protected] ~/Desktop/Projects/test_timemeasure_sched $ gcc -Wall -o -O0 test_time_measure_sched main.c -lwiringPi -lpthread -lrt
main.c: In function ‘main’:
main.c:22:33: warning: unused variable ‘rem’ [-Wunused-variable]
main.c:22:28: warning: variable ‘req’ set but not used [-Wunused-but-set-variable]
main.c:19:11: warning: unused variable ‘i’ [-Wunused-variable]
test_time_measure_sched: In function `_fini':
:(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.fini+0x0): first defined here
test_time_measure_sched: In function `__data_start':
:(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.data+0x0): first defined here
test_time_measure_sched: In function `__data_start':
:(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbegin.o:(.data+0x0): first defined here
test_time_measure_sched:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.rodata.cst4+0x0): first defined here
test_time_measure_sched: In function `_start':
:(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.text+0x0): first defined here
test_time_measure_sched: In function `_init':
:(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.init+0x0): first defined here
/tmp/cc5At86c.o: In function `main':
main.c:(.text+0x0): multiple definition of `main'
test_time_measure_sched::(.text+0xac): first defined here
collect2: ld returned 1 exit status
내가 무엇을 할 수 그 오류를 제거하려면?
고맙습니다.
감사합니다.
에릭
'-o' 옵션의 위치가 잘못되었습니다. '-o test_time_measure_sched'를 유지하십시오. –
''noppynop2.c '는 500 번 asm ("nop")'을 포함하고 있습니다 - 모든 것이 포함되어 있습니까? 스 니펫을 게시 할 수 있습니까? –
@ 존 버스 : 네, 단지 500 배의 asm ("nop") 만 포함하고, 그 이상은 아무것도 아닙니다;) – ricothebrol