프로그램 사용/gcc2013. 1. 13. 09:00
__u64의 경우 types.h를 include 하면 인식하지 못하며
long long int의 경우 gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 에서 기본적으로 인식한다.
OS가 64bit 이냐 아니냐와는 별개로 작동에는 문제가 없는듯 하기도 하고?
(현재 32bit 우분투라 아예 안될줄 알았는데 sizeof를 통해서는 크기를 돌려주기는 함)

아무튼 실험을 해보니 long long int 만 64bit(8byte)로 설정된다.
long
int
long int
long long int / __u64 uint64_t int64_t

$ cat /usr/include/linux/types.h
typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
typedef __u32 __bitwise __be32;
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;

typedef __u16 __bitwise __sum16;
typedef __u32 __bitwise __wsum;

$ cat /usr/include/limits.h
/* Minimum and maximum values a `signed int' can hold.  */
#  define INT_MIN       (-INT_MAX - 1)
#  define INT_MAX       2147483647

/* Maximum value an `unsigned int' can hold.  (Minimum is 0.)  */
#  define UINT_MAX      4294967295U

/* Minimum and maximum values a `signed long int' can hold.  */
#  if __WORDSIZE == 64
#   define LONG_MAX     9223372036854775807L
#  else
#   define LONG_MAX     2147483647L
#  endif
#  define LONG_MIN      (-LONG_MAX - 1L)

/* Maximum value an `unsigned long int' can hold.  (Minimum is 0.)  */
#  if __WORDSIZE == 64
#   define ULONG_MAX    18446744073709551615UL
#  else
#   define ULONG_MAX    4294967295UL
#  endif

#  ifdef __USE_ISOC99

/* Minimum and maximum values a `signed long long int' can hold.  */
#   define LLONG_MAX    9223372036854775807LL
#   define LLONG_MIN    (-LLONG_MAX - 1LL)

/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
#   define ULLONG_MAX   18446744073709551615ULL

#  endif /* ISO C99 */

$ cat /usr/include/stdint.h
/* There is some amount of overlap with sys/types.h as known by inet code */
#ifndef __int8_t_defined
# define __int8_t_defined
typedef signed char             int8_t;
typedef short int               int16_t;
typedef int                     int32_t;
# if __WORDSIZE == 64
typedef long int                int64_t;
# else
__extension__
typedef long long int           int64_t;
# endif
#endif

/* Unsigned.  */
typedef unsigned char           uint8_t;
typedef unsigned short int      uint16_t;
#ifndef __uint32_t_defined
typedef unsigned int            uint32_t;
# define __uint32_t_defined
#endif
#if __WORDSIZE == 64
typedef unsigned long int       uint64_t;
#else
__extension__
typedef unsigned long long int  uint64_t;
#endif

Posted by 구차니
프로그램 사용/gcc2012. 2. 12. 11:19
gcc 도움말에 의하면 아래의 경로에서 기본적으로 include 파일을 찾게 된다는데

2.3 Search Path

GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with #include <file> in:

     /usr/local/include
     libdir/gcc/target/version/include
     /usr/target/include
     /usr/include

[링크 : http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html]  

음.. 저 긴 옵션을 다 줘야 하는 이유는 먼지 모르겠지만,
아무튼 확인해보면 /usr/local/include가 /usr/include 보다 우선적으로 검색하게 된다.
그런 이유로 opencv가 /usr/local/include에 설치되는 듯하다.
$ g++ -v -x c -E -
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-E' '-shared-libgcc' '-mtune=generic' '-march=i486'
 /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1 -E -quiet -v - -D_FORTIFY_SOURCE=2 -mtune=generic -march=i486 -fstack-protector
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
 /usr/include
End of search list.

[링크 : http://gcc.gnu.org/ml/gcc-help/2007-09/msg00216.html]   

'프로그램 사용 > gcc' 카테고리의 다른 글

ubuntu gcc가 바보  (2) 2013.09.19
gcc 64bit 확장  (0) 2013.01.13
gcc의 2진수 표기법  (0) 2011.12.28
c++ 컴파일 오류 - error: extra qualification  (0) 2011.10.12
gcc 컴파일 단계별 옵션  (0) 2010.03.04
Posted by 구차니
프로그램 사용/gcc2011. 12. 28. 11:05
기억력 감퇴인가.. 아무튼 c언어에서는 2진수 표기를 할 방법이 없어서
16진수로만 하는데 검색을 하다 보니 이상한 문장을 발견 -_-
  
보통 c에서는 00111111b 와 같이 사용하는데, 2진수로 바로 쓰려면 어떻게 해야하나요?
아시는 분 있으면 답변해주시면 감사하겠습니다. ^^; 

[링크 : http://www.terabank.co.kr/bbs/zboard.php?id=comunity01...no=1343]
[링크 : http://donghwada.tistory.com/entry/ATmega-Pin-Configurations-DDR-PORT-PIN]

gcc에서 제공하는 비표준 C문법으로
0x0000 이라고 16진수를 입력하듯
0b0000 이라고 2진수를 입력이 가능하다.

물론 vi에서도 인식되지 않는 문법이라 문법강조도 되지 않음 -_-
+ winavr역시 gcc 의 한 종류 이므로 이러한 문법을 허용한다.

$ vi temp.c 
  1 #include <stdio.h>
  2
  3 void main()
  4 {
  5     unsigned char binval = 0b1000000;
  6     unsigned char binval2= 10000;
  7 }
 
$ gcc temp.c
temp.c: In function ‘main’:
temp.c:6: warning: large integer implicitly truncated to unsigned type 

Most people use hexadecimal for binary numbers in C.
(GCC and some other compilers have an non-standard 0b####### extension

[링크 : http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=64658]  

흐음.. C99 표준에 넣으려다가 기각당했군 -ㅁ-
dl8dtl - Nov 26, 2006 - 08:38 PM
Post subject: RE: Binary constants in IAR C ?
> Binary notation was added in C99 if I remember correctly. 

No, it's been rejected by the committee. 

In the C99 rationale, you can find under 6.4.4.1 Integer constants: 

``A proposal to add binary constants was rejected due to 
lack of precedent and insufficient utility.'' 

So please tell your (national) standards body there *is* sufficient utility for 
it. As for the first part, I'm trying to get the 0b patch officially 
as an extension into GCC. Once that happened, there will be at least 
one very prominent C implementation that sets a precedent case. ;-) 
All those microcontroller implementations are probably nothing the ISO 
C standardization body might be aware of, but for sure, GCC is. 

> IAR is not fully up to C99 yet, 

It's about the most complete C99 implementation I've seen.  

[링크 : http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=44082&start=0]

그나저나.. 0000b 는 누구 문법일까?
Posted by 구차니
프로그램 사용/gcc2011. 10. 12. 23:57
gcc 버전에 따른 오류라고 하는데
우분투에서 --v로 확인해보면 해당 버전도 아닌데 흐음.. 왜이럴까..

$ gcc --v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)  


아무튼, "error: extra qualification" 이녀석은
제한자(qualification / 자격) 해당 함수/메소드의 클래스를 제한해주는 역활인데
아래의 소스에 대해서
 void Mesh::HSVtoRGB( double *r, double *g, double *b, double h, double s=1 , double v=1 ); 

이러한 에러를 발생해 낸다.
 mesh.h:229: error: extra qualification ‘Mesh::’ on member ‘HSVtoRGB’

mesh.cpp에 Mesh::HSVtoRGB() 함수가 존재함에도 왜이런 에러가 뜰려나 후우...
프로토 타입이랑 원 함수랑 s=1 , v=1 부분이 달라서 동일하게 해도 여전히 에러가 난다 ㅠ.ㅠ


Posted by 구차니
프로그램 사용/gcc2010. 3. 4. 11:23

학교에서 컴파일러 배운지도 오래되서 기억도 가물가물하는데,
아무튼 컴파일이라는 과정은 생각보다 여러단계를 거친다.

1단계는 #define 이나 #include 등의 매크로프로세서를 처리하는 과정
2단계는 매크로 처리된 C언어를 컴파일하는 과정(문법 확인)
3단계를 컴파일 된 결과물인 어셈블리 코드를 오브젝트로 변환하는 과정
4단계는 오브젝트들을 서로 묶어주는 과정
5단계는 이런 묶인 녀석들을 메모리에서 돌아가도록 하는 로더라는 녀석을 붙이는 과정을 거친다.

이렇게 단계가 나누어져 있다 보니,
gcc에서는 단계별 결과를 추출해 낼수 있다.

예를들어, 매크로가 복잡해서 소스 추적이 힘들경우
매크로 프로세서를 거친 결과만을 뽑아내고 싶다고 한다면
gcc -E 옵션을 사용하면 매크로가 제외된(처리된) 결과가 stdout으로 나온다.
gcc -E 소스파일 > 저장할 파일
이런식으로 한단계만 거쳐 디버깅에 사용할 수도 있다.

추가적으로, Makefile 에서
CPP 는 C++이 아니라 C PreProcessor = 매크로 프로세서 이고
CC 는 C Compiler
AS 는 Assembler
LD 는 Loader (링커) 를 의미한다.

2010/03/02 - [프로그램 사용/gcc] - gcc의 linker 옵션
2010/01/27 - [프로그램 사용/gcc] - gcc 매크로만 확장하기 (preprocessor/전처리기)
Posted by 구차니
프로그램 사용/gcc2010. 3. 2. 17:34
gcc 옵션중에 헷갈리는게 있다.
-L과 -l이 그녀석인데, 비슷비슷해서 조금 헷갈린다.

아무튼 -L은 디렉토리(경로)를
-l은 특정 라이브러리 파일을 설정하는데 사용된다.

       -l library
           Search the library named library when linking.  (The second alternative with the library as a separate argu-
           ment is only for POSIX compliance and is not recommended.)

           It makes a difference where in the command you write this option; the linker searches and processes libraries
           and object files in the order they are specified.  Thus, foo.o -lz bar.o searches library z after file foo.o
           but before bar.o.  If bar.o refers to functions in z, those functions may not be loaded.

           The linker searches a standard list of directories for the library, which is actually a file named libli-
           brary.a.  The linker then uses this file as if it had been specified precisely by name.

           The directories searched include several standard system directories plus any that you specify with -L.

           Normally the files found this way are library files---archive files whose members are object files.  The
           linker handles an archive file by scanning through it for members which define symbols that have so far been
           referenced but not defined.  But if the file that is found is an ordinary object file, it is linked in the
           usual fashion.  The only difference between using an -l option and specifying a file name is that -l sur-
           rounds library with lib and .a and searches several directories.

       -Ldir
           Add directory dir to the list of directories to be searched for -l.

       LIBRARY_PATH
           The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH.  When configured as a
           native compiler, GCC tries the directories thus specified when searching for special linker files, if it
           can’t find them using GCC_EXEC_PREFIX.  Linking using GCC also uses these directories when searching for
           ordinary libraries for the -l option (but directories specified with -L come first).

[링크 : http://linux.die.net/man/1/gcc]
Posted by 구차니
프로그램 사용/gcc2010. 2. 11. 16:05
gcc -static [파일이름]

위와 같이 컴파일 하면 정적으로 링크한다.
예를들어 /sbin/init 등이 제대로 되는지 확인할때
init를 임의로 만들어 정적으로 컴파일 후에 /sbin/init 치환하면
/lib 뒤질일 없이 바로 실행이 가능하므로 디버깅이 용이해진다.

하지만, 용량이 무지 커지니 주의!

-static
On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.

[링크: http://linux.die.net/man/1/gcc]

[링크 : http://www.faqs.org/docs/Linux-mini/NFS-Root.html#toc5]
[링크 : http://lists.busybox.net/pipermail/busybox/2007-May/061479.html]
[링크 : http://www.linuxquestions.org/questions/linux-kernel-70/2.4.36.3-busyboxs-init-hangs-at-freeing-unused-kernel-memory-645556/]
Posted by 구차니
프로그램 사용/gcc2010. 2. 10. 10:45
gcc에서 지원하고 있는 언어를 확인하고 싶을때 사용하는 방법으로
gcc의 버전 정보중에 --enable-languages 의 값을 확인하면 된다.

$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)

$ sh4-linux-gcc -v
Using built-in specs.
Target: sh4-linux
Configured with: ../configure --host=i686-pc-linux-gnu --target=sh4-linux --prefix=/opt/STM/STLinux-2.2/devkit/sh4 --exec-prefix=/opt/STM/STLinux-2.2/devkit/sh4 --bindir=/opt/STM/STLinux-2.2/devkit/sh4/bin --sbindir=/opt/STM/STLinux-2.2/devkit/sh4/sbin --sysconfdir=/opt/STM/STLinux-2.2/devkit/sh4/etc --datadir=/opt/STM/STLinux-2.2/devkit/sh4/share --includedir=/opt/STM/STLinux-2.2/devkit/sh4/include --libdir=/opt/STM/STLinux-2.2/devkit/sh4/lib --libexecdir=/opt/STM/STLinux-2.2/devkit/sh4/libexec --localstatedir=/opt/STM/STLinux-2.2/devkit/sh4/var --sharedstatedir=/opt/STM/STLinux-2.2/devkit/sh4/share --mandir=/opt/STM/STLinux-2.2/devkit/sh4/man --infodir=/opt/STM/STLinux-2.2/devkit/sh4/info --program-prefix=sh4-linux- --with-local-prefix=/opt/STM/STLinux-2.2/devkit/sh4 --with-sysroot=/opt/STM/STLinux-2.2/devkit/sh4/target --enable-languages=c,c++ --enable-threads=posix --enable-nls --enable-c99 --enable-long-long --with-system-zlib --enable-shared --enable-multilib --enable-symvers=gnu --enable-__cxa_atexit --with-gxx-include-dir=${prefix}/target/usr/include/c++/4.1.1
Thread model: posix
gcc version 4.1.1 (STMicroelectronics/Linux Base 4.1.1-23)


[링크 : http://korea.gnu.org/manual/release/install/configure.html]
Posted by 구차니
프로그램 사용/gcc2010. 1. 27. 17:18
#if 문이라던가 각종 전처리기용 문구들은
여러가지 확장을 통해서 컴파일을 하기 때문에 source insight 등의 힘을 빌려도 분석하기 어려운 면이 있다.

일반적으로 컴파일러는 전처리기 - 컴파일 - 어셈블 - 링크 과정을 거치는데(아마도?)
전처리기 까지만 거친 결과를 stdout 으로 출력해준다.

$ man gcc
       -E  Stop after the preprocessing stage; do not run the compiler proper.
            The output is in the form of preprocessed source code, which is sent to the standard output.

           Input files which don't require preprocessing are ignored.

[링크 : http://linux.die.net/man/1/gcc]

$ cat test.c
#if 1
int test;
#else
int tt;
#endif

int main()
{
        return 0;
}

$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"

int test;




int main()
{
 return 0;
}


#include 하는 모든 파일을 확장하기 때문에, #include <stdio.h>만 해도 내용이 엄청 길어진다.
그리고 줄단위로 처리하기 때문에 사라진 #if 문 대신 엔터만 남아 위와 같이 휑~하게 나왔다.


[링크 : http://cafe.naver.com/devctrl/949]
Posted by 구차니
프로그램 사용/gcc2009. 9. 21. 21:33
--sysroot=dir
    Use dir as the logical root directory for headers and libraries. For example, if the compiler would normally search for headers in /usr/include and libraries in /usr/lib, it will instead search dir/usr/include and dir/usr/lib.

    If you use both this option and the -isysroot option, then the --sysroot option will apply to libraries, but the -isysroot option will apply to header files.

    The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of --sysroot will still work, but the library aspect will not.

-isysroot dir
    This option is like the --sysroot option, but applies only to header files.  See the --sysroot option for
    more information.

[링크 : http://linux.die.net/man/1/gcc]

기본값은 /usr/include 인데, -sysroot로 기본 디렉토리를 변경 시키면
<stdio.h> 와 같은 파일도 찾지 못해 link 에러를 발생시키며 컴파일이 실패된다.

$ more test.c
#include <stdio.h>

int main(int argc, char **argv)
{
        printf("hello world\n");
        return 0;
}

$ gcc --sysroot=/ test.c
/usr/bin/ld: this linker was not configured to use sysroots
collect2: ld returned 1 exit status



아무튼, 크로스컴파일과 같이 특정 include 디렉토리를 사용해야 할 경우,
--sysroot 를 이용해서 변경하면 될 듯 하다
Posted by 구차니