티스토리 뷰

반응형

여기에서 발췌


Libraries

Libraries are files whose names end in .a, or possibly .so. To designate a library, you can specify an absolute or relative path name or use the -l (lowercase letter L) flag in the form -lName. The last form designates a libName.afile, or when the rtl option is used, a libName.so file to be searched for in several directories. These search directories include any directories that are specified by -L flags and the standard library directories /usr/lib and /lib.

Note
If you specify a shared object, or an archive file containing a shared object, with an absolute or relative path name, instead of with the -lName flag, the path name is included in the import file ID string in the loader section of the output file. You can override this behavior with the -bnoipath option.

google 번역


Libraries

라이브러리는 이름이 .a 또는 .so로 끝나는 파일입니다. 라이브러리를 지정하려면 절대 또는 상대 경로 이름을 지정하거나 -lName 형식으로 -l (소문자 L) 플래그를 사용할 수 있습니다. 마지막 형식은 libName.a 파일을 지정하거나 rtl 옵션을 사용하면 여러 디렉토리에서 libName.so 파일을 검색합니다. 이러한 검색 디렉토리에는 -L 플래그로 지정된 디렉토리와 표준 라이브러리 디렉토리 / usr / lib 및 / lib가 포함됩니다.


Note

-lName 플래그 대신에 공유 오브젝트 또는 공유 오브젝트를 포함하는 아카이브 파일을 절대 또는 상대 경로 이름과 함께 지정하면 경로 이름이 출력의 로더 섹션에있는 임포트 파일 ID 문자열에 포함됩니다 파일. -bnoipath 옵션을 사용하여이 동작을 무시할 수 있습니다.


------------------------------------------------------------------------------


shared library(.so)을 사용하여 gcc로 빌드 시 "-Wl,-brtl" 옵션을 통해 -l{Library Name}을 사용하여 .so을 사용할 수 있다.

또는, 직접 .so 파일명을 직접 입력 할 수 있는데 빌드 후 출력되는 파일의 .so 정보에는 빌드 할 당시의 .so 경로 정보가 같이 포함되고, 출력 파일을 실행 시 loader는 포함 된 .so 경로에서 .so를 찾게 되고 없을 경우 실행이 되지 않는다. 이 때 "-Wl,-bnoipath" 옵션을 설정하여 빌드 할 때 .so 파일의 경로를 무시하도록 할 수 있다.


/root/test/lib/libtest.so가 있을 때 main.c를 빌드


-brtl 을 사용 할 경우

gcc -Wl,-brtl -L/root/test/lib -ltest -o main main.c


-bnoipath 를 사용 할 경우

gcc -Wl,-noipath /root/test/lib/libtest.so -o main main.c



반응형

'DEV Tools > gcc' 카테고리의 다른 글

centos 7에서 gcc로 32bit compile  (0) 2018.01.31
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함