2012년 독서 목록
gcc/g++ linking option
어제오늘의 멍청한 짓에서 배움.gcc/g++ linking시 object file이나 library file이 지정된 순서대로 symbol을 찾는다.gcc option 설명을 인용하면,
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.
bar.o에서 호출하는 함수를 모르는 상태에서 z의 해당 함수가 load되지 않기 때문이다. 내가 한 짓도 예제와 똑같은데, 이것 때문에 어제부터 undefined symbol 에러메시지를 해결하지 못하고 있었음.게다가 난 저 설명을 보고도 착각한 게, z의 함수 중에서 참조된 것들만 load되는 것을 몰랐기 때문에 당연히 먼저 나와야 한다고 생각했다. 결과가 기대와 정반대인 건 당연지사.단, 이것은 .a archive에 대한 설명이므로 shared object의 경우는 좀 다를 수 있다. 마찬가지로 확인해봐야함.
- 2012/03/28 15:48 에 작성