2015. 6. 4. 15:59

최근에 컴파일 중 발생한 이슈였다.


/user/bin/ld: warning: lA.so.0, needed by lA.so, not found (try using -rpath or -rpath-link)


collect2: ld returned 1 exit status

make: *** [test.out] 오류 1

컴파일러가 친절히 using -rpath or -rpath-link를 사용하라고 안내해 줬지만, 

궁금한 점이 있어 조금 더 찾아봤다.


우선 $LD_LIBRARY_PATH에 lA.so가 들어있는 path를 잡아줬더니 저 문구가 뜨지 않고 정상적으로 컴파일 되었다.


 export LD_LIBRARY_PATH={lA.so가들어있는디렉토리패스}:$LD_LIBRARY_PATH


그 이유를 살펴보니 다음과 같았다.


○ 링커들은 다음과 같은 검색경로들을 사용해서 공유 라이브러리들을 찾는다.

1. -rpath-link 옵션들에 의해 지정된 임의의 디렉터리들

2. -rpath 옵션들에 의해 지정된 임의의 디렉터리들.

3. ELF 시스템에서 -rpath와 -rpath-link 옵션들이 사용되지 않으면 LD_RUN_PATH환경변수를 참조한다.

4. 원시(native)링커의 경우 환경 변수 LD_LIBRARY_PATH의 내용을 참고한다.

5. 디폴트 디렉터리들, 일반적으로 '/lib'와 '/user/lib'.

>> 요구된 공유 라이브러리가 발견되지 않으면 링커는 경고를 발생하고 링크를 계속한다.





※ -rpath와 -rpath-link옵션의 차이

-rpath옵션들로 지정된 디렉터리들은 실행파일안에 포함되고 실행시 사용

-rpath-link 옵션은 단지 링크할 때만 영향을 미친다.


현재 개발하고 있는 프로그램의 경우, 동작시 LD_LIBRARY_PATH에 링크를 export해 사용하므로,

-rpath-link옵션을 추가해 사용해 주었다.



-Wl,-rpath-link,{lA.so가들어있는디렉토리패스}

단 사용할 때 -Wl,-rpath-link 로 사용해 주어야 하는데 그 이유는,

-Wl옵션은 gcc를 거치지 않고 바로 링커에 옵션을 전하려 할 때 사용한다.

 -Wl,option

   Pass option as an option to the linker.  If option contains commas, it is split into

  multiple options at the commas.  

  You can use this syntax to pass an argument to the option.

  For example, -Wl,-Map,output.map passes -Map output.map to the linker.  When using the GNU

  linker, you can also get the same effect with -Wl,-Map=output.map.

출처 : g++ man page




해당 옵션들에 대한 자세한 설명들은 아래와 같다.(참조)


-rpath dir

디렉터리를 실시간 라이브러리 검색 경로에 추가한다. 이것은 ELF 실행 파일을 공유 오브젝트들과 링크할 때 사용된다. 모든 -rpath 매개변수들은 조합되어 실시간 링커에게 전달된다. 그러면 이것은 그들을 사용해서 실시간에 공유 오브젝트들을 찾는다. -rpath 옵션은 또한 링크에서 명시적으로 포함된 공유 오브젝트들에 의해서 필요한 공유 오브젝트들을 찾을 때도 사용된다; -rpath-link 옵션의 설명을 보자. -rpath가 ELF 실행파일을 링크할 때 사용되지 않으면 환경 변수 LD_RUN_PATH의 내용물이, 정의되었다면, 사용될 것이다. -rpath 옵션은 SunOS에서도 사용될 수 있다. 디폴트로 SunOS에서 링커는 주어진 -L 옵션들 중에서 실시간 검색 패치(patch)를 구성할 것이다. -rpath 옵션이 사용되면 실시간 검색 경로는 -rpath 옵션들을 명시적으로 사용하여 구성될 것이고 -L 옵션들을 무시할 것이다. 이것은 NFC 마운트된 파일시스템들로부터 가져온 것일 수 있는, 많은 -L 옵션들을 더하는 gcc를 사용할 때 유용할 수 있다. ELF 링커들과의 호환성을 위해서 파일 이름이 아니라, 디렉터리 이름 뒤에 따라 붙은 -R 옵션이 주어지면 이것은 -rpath 옵션으로 취급된다.

-rpath-link DIR

ELF 또는 SunOS를 사용할 때 한가지 공유 라이브러리는 다른 것을 요구할 수도 있다. 이것은 ld -shared 링크가 입력 파일들 중의 하나로써 공유 라이브러리를 포함할 때 일어난다. 링커가 비-공유, 비-재배치 링크를 수행할 때 그런 종속성을 만나면 자동으로 요구된 공유 라이브러리를 찾으려고 하고 명시적으로 포함되지 않았다면 그것을 링크에 포함시킨다. 그런 경우 -rpath-link 옵션은 검색할 첫번째 디렉터리들을 지정한다. -rpath-link 옵션은 콜론(:)으로 분리된 이름들 리스트를 지정함으로써 또는 여러번 나타남으로써 디렉터리 이름의 순서를 지정할 수도 있다. 

참고자료 : http://korea.gnu.org/manual/release/ld/ld-sjp/ld-ko_2.html




   -rpath=dir

           Add a directory to the runtime library search path.  This is used when linking an ELF

           executable with shared objects.  All -rpath arguments are concatenated and passed to the

           runtime linker, which uses them to locate shared objects at runtime.  The -rpath option is

           also used when locating shared objects which are needed by shared objects explicitly

           included in the link; see the description of the -rpath-link option.  If -rpath is not used

           when linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will

           be used if it is defined.


           The -rpath option may also be used on SunOS.  By default, on SunOS, the linker will form a

           runtime search patch out of all the -L options it is given.  If a -rpath option is used, the

           runtime search path will be formed exclusively using the -rpath options, ignoring the -L

           options.  This can be useful when using gcc, which adds many -L options which may be on NFS

           mounted file systems.


           For compatibility with other ELF linkers, if the -R option is followed by a directory name,

           rather than a file name, it is treated as the -rpath option.


       -rpath-link=dir

           When using ELF or SunOS, one shared library may require another.  This happens when an "ld

           -shared" link includes a shared library as one of the input files.


           When the linker encounters such a dependency when doing a non-shared, non-relocatable link,

           it will automatically try to locate the required shared library and include it in the link,

           if it is not included explicitly.  In such a case, the -rpath-link option specifies the

           first set of directories to search.  The -rpath-link option may specify a sequence of

           directory names either by specifying a list of names separated by colons, or by appearing

           multiple times.


           This option should be used with caution as it overrides the search path that may have been

           hard compiled into a shared library. In such a case it is possible to use unintentionally a

           different search path than the runtime linker would do.


           The linker uses the following search paths to locate required shared libraries:


           1.  Any directories specified by -rpath-link options.


           2.  Any directories specified by -rpath options.  The difference between -rpath and

               -rpath-link is that directories specified by -rpath options are included in the

               executable and used at runtime, whereas the -rpath-link option is only effective at link

               time. Searching -rpath in this way is only supported by native linkers and cross linkers

               which have been configured with the --with-sysroot option.


           3.  On an ELF system, for native linkers, if the -rpath and -rpath-link options were not

               used, search the contents of the environment variable "LD_RUN_PATH".


           4.  On SunOS, if the -rpath option was not used, search any directories specified using -L

               options.


           5.  For a native linker, the search the contents of the environment variable

               "LD_LIBRARY_PATH".


           6.  For a native ELF linker, the directories in "DT_RUNPATH" or "DT_RPATH" of a shared

               library are searched for shared libraries needed by it. The "DT_RPATH" entries are

               ignored if "DT_RUNPATH" entries exist.


           7.  The default directories, normally /lib and /usr/lib.


           8.  For a native linker on an ELF system, if the file /etc/ld.so.conf exists, the list of

               directories found in that file.


           If the required shared library is not found, the linker will issue a warning and continue

           with the link.

(ld man page)


Posted by Triany
2015. 4. 11. 15:52

출처 : http://ko.wikipedia.org/wiki/%EC%A0%9C%EC%96%B4_%EB%AC%B8%EC%9E%90


컴퓨팅 및 전자통신 환경에서 제어 문자 또는 비인쇄 문자는 문자 집합의 특별한 문자가 있다.



아스키에서의 제어 문자[편집]


제어 문자표[편집]

2진법10진법8진법16진법문자설명
0000 000000000000NULNULL 문자
0000 000100100101SOH헤더 시작(Start Of Header)
0000 001000200202STX본문 시작, 헤더 종료(Start of TeXt)
0000 001100300303ETX본문 종료(End of TeXt)
0000 010000400404EOT전송 종료, 데이터 링크 초기화(End Of Transmission)
0000 010100500505ENQ응답 요구(ENQuiry)
0000 011000600606ACK긍정응답(ACKnowledge)
0000 011100700707BEL경고음(BELl)
0000 100000801008BS백스페이스(BackSpace)
0000 100100901109HT수평 탭(Horizontal Tab)
0000 10100100120ALF개행(Line Feed)
0000 10110110130BVT수직 탭(Vertical Tab)
0000 11000120140CFF다음 페이지(Form Feed)
0000 11010130150DCR복귀(Carriage Return)
0000 11100140160ESO확장문자 시작(Shift Out)
0000 11110150170FSI확장문자 종료(Shift In)
0001 000001602010DLE전송제어 확장(Data Link Escape)
0001 000101702111DC1장치 제어(Device Control 1)
0001 000101802212DC2장치 제어(Device Control 2)
0001 000101902313DC3장치 제어(Device Control 3)
0001 000102002414DC4장치 제어(Device Control 4)
0001 010102102515NAK부정응답(Negative AcKnowledge)
0001 011002202616SYN동기(SYNnchronous idle)
0001 011102302717ETB전송블록 종료(End of Transmission Block)
0001 100002403018CAN취소(CANcel)
0001 100102503119EM매체 종료(End of Medium)
0001 10100260321ASUB치환(SUBstitute)
0001 10110270331BESC제어기능 추가(ESCape)
0001 11000280341CFS파일경계 할당(File Seperator)
0001 11010290351DGS레코드 그룹경계 할당(Group Seperator)
0001 11100300361ERS레코드경계 할당(Record Seperator)
0001 11110310371FUS장치경계 할당(Unit Seperator)


나는 이 제어문자를 비 인쇄문자 측면으로 조명해 보고 싶은데!(지금!)


이 비인쇄 문자들은 하나의 라인에 여러 항목들을 담을때 구분자로 쓰기 적당하다!

http://www.naver.com^Ghttp://www.google.com^Ghttp://www.daum.net


이렇게 한줄로 연결되 있는경우 제어문자를 사용하여 split해서 쓸 수 있다. 

Posted by Triany
2015. 3. 9. 21:21

복사생성자가 호출되는 시점은 언제일까?

복사생성자

: 자기 자신과 같은 형태의(자료형의) 객체를 인자로 받을 수 있는 생성자를 복사생성자라고 한다.

AAA(const AAA& a)

{

}



1. 기존에 생성된 객체로 새로운 객체를 초기화하는 경우

int main()

{

   Person p1;

   Person p2=p1;  //기존에 생성된 객체로 새로운 객체 초기화

}



2. 함수 호출 시 객체를 값에 의해 전달하는 경우

void func(Person p)


3. 함수 내에서 객체를 값에 의해 리턴하는 경우

Person fun2()

{
   Person p;
   return p;
}


>> 부록

디폴트 복사 새성자 존재

디폴트 복사 생성자 - 자동으로 삽입되는 복사 생성자

: 멤버 변수대 멤버 변수의 복사를 수행


출처: 열혈강의 c++프로그래밍_윤성우

Posted by Triany