2

나는 boost :: interprocess :: container 문자열을 공유 메모리에 쓰고 다른 하나를 읽는 작은 프로그램을 작성했습니다.boost :: interprocess로 컴파일 링커 오류가 발생했습니다.

나는 다음과 링커 오류가 점점 오전 :

g++ SharedMemTest.cpp -L /usr/lib/x86_64-linux-gnu/librt.a 
/tmp/cc5v7WKj.o: In function `boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)': 
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x1c): undefined reference to `pthread_mutexattr_init' 
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x31): undefined reference to `pthread_mutexattr_setpshared' 
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x4c): undefined reference to `pthread_mutexattr_settype' 
/tmp/cc5v7WKj.o: In function `boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()': 
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperD2Ev[_ZN5boost12interprocess6detail17mutexattr_wrapperD5Ev]+0x14): undefined reference to `pthread_mutexattr_destroy' 
/tmp/cc5v7WKj.o: In function `boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)': 
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0xe0): undefined reference to `shm_open' 
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x116): undefined reference to `shm_open' 
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x16c): undefined reference to `shm_open' 
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x1c0): undefined reference to `shm_open' 
/tmp/cc5v7WKj.o: In function `boost::interprocess::shared_memory_object::remove(char const*)': 
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object6removeEPKc[boost::interprocess::shared_memory_object::remove(char const*)]+0x40): undefined reference to `shm_unlink' 

을 나는 또한 다음과 같이 연결 시도 : 이러한 명령 중 어느 것도 작동하지 않습니다

g++ -c SharedMemTest.cpp 
g++ -L /usr/lib/x86_64-linux-gnu/librt.a SharedMemTest.o -o SharedMemTest 

하지만. 누군가가이 간단한 예제를 어떻게 컴파일 할 수 있는지 말해 주시겠습니까?

+0

'g ++ -lpthread -lrt SharedMemTest.cpp' (pthread 및 rt 라이브러리 포함). 최소한 인터넷 검색을 해봤 니? – nothrow

+2

@ Yossarian, 귀하의 권장 사항이 작동하지 않기 때문에 분명히. Google이 모든 것에 대한 해답을 갖고 있다면, 우리는 그렇게 할 필요가 없을 것입니다. – czchlong

+3

@czchlong : 그의 추천은 작동하지만,'g ++ SharedMemTest.cpp -lpthread -lrt' (순서 문제)를 시도해보십시오. – ildjarn

답변

0

-L에 대한 인수는 디렉토리 여야하지만 그 뒤에 라이브러리 파일 이름을 넣을 것입니다. 아마도 -l rt을 의미했을 것입니다. 다른 사람들은 이미 -l pthread을 제안했지만 -pthread을 사용하여 pthreads 라이브러리에 링크 할 수도있었습니다.