728x90
반응형
Zigbex SHT11 제어하여 온도, 습도를 구하여 소수점 포함하여 출력하기
프로그램의 최적화를 위해 컴파일러는 많은 옵션을 제공한다.
따라서 필요한 옵션을 적절히 사용하여 컴파일해야 같은 함수를 사용한 코드라 하더라도 코드 사이즈 및 수행 시간을 줄일 수 있고, 그로 인해 성능을 향상시킬 수 있다.
반대로 더 정밀한 계산을 위해 옵션을 사용해야 하는 경우도 있다.
임베디드 디바이스는 제약사항이 많기 때문에 이러한 옵션을 적절히 사용하는 것이 더욱 중요하다.
AVR CORE는 부동소수점 연산을 수행하는데 많은 사이클이 필요하다.
printf("%f", 1.234) 같은 경우도 부동소수점 연산이 필요한 경우이다.
그래서 avr-gcc에서는 printf()와 관련된 세가지 라이브러리를 만들어 필요한 경우에 해당 라이브러리를 사용할 수 있게 해 놓았다.
1. 부동소수점 변환을 제외한 모든 변환이 가능한 vfprintf() (glibc.a에 포함)
2. 간단한 정수와 문자열 변환만 가능한 vfprintf() (libprintf_min.a에 포함)
3. 부동소수점 변환까지 가능한 vfprintf() (libprintf_flt.a에 포함)
참고)
1) printf()는 내부적으로 vprintf()를 호출하고, vprintf()는 다시 vfprintf()를 호출한다.
2) libprintf_flt.a를 사용하려면 libm.a이 필요하다.
(avr-gcc에서 작성된 Makefile에는 libm.a 라이브러리가 기본적으로 포함되어 있음)
순서)
1) sprintf(buf, "%2.3f", 12.345); --> 실행하면 '?' 등의 원하지 않은 값이 나온다.
2) Makefile을 열어 아래와 같은 부분을 찾아 첫번째는 주석처리, 세번째는 주석해제를 해준다.
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB = --> #PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) --> PRINTF_LIB = $(PRINTF_LIB_FLOAT)
3) 컴파일한다.
PRINF_LIB_FLOAT는 -Wl,-u,vfprintf -lprintf_flt로 정의되어 있다.
-Wl : 링커(ld)에 직접 전달할 옵션들을 지정할 수 있게 해주는 gcc의 옵션. 각 옵션은 컴마(,)로 구분되어 있다.
-u : vfprintf라는 심볼이 아직 정의되지 않은 채 .o 파일이 만들어진 후(?) 링킹된 라이브러리 모듈에 의해 정의되도록 한다.
-lprintf_flt : libprintf_flt.a 라는 정적 라이브러리를 포함하여 실행 파일을 만든다. 소수점을 계산할 수 있는 출력 관련 함수의 라이브러리이다. -u 옵션으로 vfprintf 심볼의 주소값이 아직 정의되지 않았는데 이 라이브러리를 링크시켜 vfprintf 심볼의 주소값을 결정한다.
#링커 동작 과정
Anyway, it's simple. The linker resolves undefined references out of
the libraries specified. By the time it processes your
libprintf_flt.a library, there is an undefined reference to the symbol
printf, but that library *only* defines vfprintf. As this symbol
doesn't help resolving anything, the library is effectively skipped.
Later on, the standard library (libc.a) is processed, and it
eventually will resolve the symbol printf. This will, in turn, cause
a new undefined reference, now to vfprintf. But oh well!, your old
libprintf_flt.a has already been completely forgotten about now, so
vfprintf will also be resolved from libc.a, thus using the default
implementation.
The -uvfprintf causes the linker to start right from the beginning
with an undefined reference to vfprintf (artificially forced from the
command-line), so this reference will then be resolved from
libprintf_flt.a. When the standard library is then used to resolve
printf, this will reference a symbol vfprintf that is now already
known.
the libraries specified. By the time it processes your
libprintf_flt.a library, there is an undefined reference to the symbol
printf, but that library *only* defines vfprintf. As this symbol
doesn't help resolving anything, the library is effectively skipped.
Later on, the standard library (libc.a) is processed, and it
eventually will resolve the symbol printf. This will, in turn, cause
a new undefined reference, now to vfprintf. But oh well!, your old
libprintf_flt.a has already been completely forgotten about now, so
vfprintf will also be resolved from libc.a, thus using the default
implementation.
The -uvfprintf causes the linker to start right from the beginning
with an undefined reference to vfprintf (artificially forced from the
command-line), so this reference will then be resolved from
libprintf_flt.a. When the standard library is then used to resolve
printf, this will reference a symbol vfprintf that is now already
known.
728x90
'코스웨어 > 10년 스마트폰BSP' 카테고리의 다른 글
[BSP]업무일지 - 한경수 - 20100812 (0) | 2010.08.12 |
---|---|
[BSP]업무일지-박동수-20100811 (0) | 2010.08.11 |
[BSP]업무일지-강혜정-20100810 (1) | 2010.08.10 |
[BSP]업무일지 - 송동규 -20100809 (0) | 2010.08.09 |
[BSP]업무일지 - 김강수 -20100806 (2) | 2010.08.06 |
[BSP]업무일지 - 김병찬 -20100804 (0) | 2010.08.04 |
[BSP]2010 08/03 업무일지- 이도헌 (0) | 2010.08.03 |
[BSP]업무 일지 정홍환 0802 (0) | 2010.08.02 |