본문 바로가기

갖가지 프로그램

gcc 사용하기


gcc -o hello hello.c 에서 -o는 실행파일 명

gcc -c hello.c 를 하면 hello.o 가 생성됨

-(소문자 L)은 링크할 라이브러리 이름(확장자 제외)을 명시.  링크시에 사용
-(대문자 L)은 라이브러리를 찾을 위치를 명시 링크시에 사용
-(대문자 I)는 헤더파일을 찾을 위치를 명시 컴파일 시에 사용

실행시에 라이브러리를 적재하기 위해서는
실행전에 LD_LIBRARY_PATH 환경변수에 library 경로를 더해주어야한다.,
Eclipse에서는 Run_configuration에 있음

ex) MakeFile에서
testMain: testMakeProject.o
$(CXX) -o testMain testMakeProject.o -L/usr/local/lib -llbfgs $(CXXFLAGS)
testMakeProject.o: testMakeProject.cpp
g++ -c testMakeProject.cpp -I/EigenLibrary/

LD_RUN_PATH 나 LD_LIBRARY_PATH 같은 환경변수가 필요할 때?
"-Wl,--rpath -Wl,path/to/lib" 를 그대로 링크 시에 옵션으로 넣어줄 것
ex) $(LD) -o $@ $^ -L/usr/local/lib -llbfgs -Wl,-R,/path/to/lib

c++로 컴파일 하려면?
g++ 로 컴파일 하면 됨.

아니면 다음 옵션을 주기
-lstdc++
여기서 libstdc++-6.dll 을 실행시 요구할 때는 -static 옵션을 같이 주면 해결?

"libstdc++-6.dll" is provided by MinGW/GCC. You can use the "-static-libstdc++" swith for the linker to avoid this message, and have it directly included in "rt.exe".

Same for "libgcc_s_dw2-1.dll", use the linker switch "-static-libgcc".