2015-04-11 2 views
0

Я не могу скомпилировать свой проект. Когда я запускаю команду make, я получаю следующую ошибку.Ошибка компиляции Ошибка библиотеки undefined для `shm_open '

Если я пытаюсь скомпилировать shareMemoryWriter.cpp одна с командой г ++ -std = C++ 11 shareMemoryWriter.cpp main2.cpp -o основной -lpthread -lrt компиляции успеха

Операционная система: Linux Mint Makefile:

CC = g++ 

CFLAGS=-Wall -g -std=c++11 -lpthread -lrt 

LDFLAGS= -std=c++11 -lpthread -lrt 

SOURCES=main.cpp \ 
daq.cpp \ 
srs.cpp \ 
fec.cpp \ 
chip.cpp \ 
detector.cpp \ 
chamber.cpp \ 
chamberSpecs.cpp \ 
multilayer.cpp \ 
layer.cpp \ 
readout.cpp \ 
connector.cpp \ 
connectorSpecs.cpp \ 
createEvents.cpp \ 
event.cpp \ 
shareMemoryWriter.cpp \ 
Coordinates.cpp 

OBJECTS=$(SOURCES:.cpp=.o) 

EXECUTABLE=main 

all: $(SOURCES) $(EXECUTABLE) 

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o [email protected] 

.cpp.o: 
    $(CC) $(CFLAGS) -c $< -o [email protected] 

clean: 
    $(RM) *.o *~ $(MAIN) 

depend: $(SRCS) 
    makedepend $^ 

Make компилировать выход:

сделать

g++ -Wall -g -std=c++11 -lpthread -lrt -c main.cpp -o main.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c daq.cpp -o daq.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c srs.cpp -o srs.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c fec.cpp -o fec.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c chip.cpp -o chip.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c detector.cpp -o detector.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c chamber.cpp -o chamber.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c chamberSpecs.cpp -o chamberSpecs.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c multilayer.cpp -o multilayer.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c layer.cpp -o layer.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c readout.cpp -o readout.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c connector.cpp -o connector.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c connectorSpecs.cpp -o connectorSpecs.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c createEvents.cpp -o createEvents.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c event.cpp -o event.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c shareMemoryWriter.cpp -o shareMemoryWriter.o 
g++ -Wall -g -std=c++11 -lpthread -lrt -c Coordinates.cpp -o Coordinates.o 
g++ -std=c++11 -lpthread -lrt main.o daq.o srs.o fec.o chip.o detector.o chamber.o chamberSpecs.o multilayer.o layer.o readout.o connector.o connectorSpecs.o createEvents.o event.o shareMemoryWriter.o Coordinates.o -o main 
shareMemoryWriter.o: In function `boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::ipcdetail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)': 
/usr/include/boost/interprocess/shared_memory_object.hpp:309: undefined reference to `shm_open' 
/usr/include/boost/interprocess/shared_memory_object.hpp:315: undefined reference to `shm_open' 
/usr/include/boost/interprocess/shared_memory_object.hpp:327: undefined reference to `shm_open' 
/usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference to `shm_open' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::mutexattr_wrapper::mutexattr_wrapper(bool)': 
/usr/include/boost/interprocess/sync/posix/pthread_helpers.hpp:37: undefined reference to `pthread_mutexattr_init' 
/usr/include/boost/interprocess/sync/posix/pthread_helpers.hpp:38: undefined reference to `pthread_mutexattr_setpshared' 
/usr/include/boost/interprocess/sync/posix/pthread_helpers.hpp:40: undefined reference to `pthread_mutexattr_settype' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::mutexattr_wrapper::~mutexattr_wrapper()': 
/usr/include/boost/interprocess/sync/posix/pthread_helpers.hpp:45: undefined reference to `pthread_mutexattr_destroy' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::posix_condition::posix_condition()': 
/usr/include/boost/interprocess/sync/posix/condition.hpp:132: undefined reference to `pthread_condattr_setpshared' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::semaphore_open(sem_t*&, boost::interprocess::ipcdetail::create_enum_t, char const*, unsigned int, boost::interprocess::permissions const&)': 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:61: undefined reference to `sem_open' 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:69: undefined reference to `sem_open' 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:77: undefined reference to `sem_open' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::semaphore_close(sem_t*)': 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:105: undefined reference to `sem_close' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::semaphore_post(sem_t*)': 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:148: undefined reference to `sem_post' 
shareMemoryWriter.o: In function `boost::interprocess::ipcdetail::semaphore_try_wait(sem_t*)': 
/usr/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp:164: undefined reference to `sem_trywait' 
collect2: error: ld returned 1 exit status 
make: *** [main] Error 1 

ответ

0

Не делайте этого:

CFLAGS=-Wall -g -std=c++11 -lpthread -lrt

компоновщика флаги не принадлежат на строке компиляции, только на линии линии.

Не делайте этого, либо:

LDFLAGS = -std = C++ 11 -lpthread -lrt

-std=c++11 является флагом компиляции, и не принадлежит на вашем линии связи.

Это:

$(CC) $(LDFLAGS) $(OBJECTS) -o [email protected]

ставит библиотеки в начале линии связи. Они должны быть на конце . This answer объясняет, почему это важно.

+1

Спасибо за ответ меняю CFLAGS = -g -Wall -std = C++ 11 -lpthread -lrt в CFLAGS = -std = C++ 11 -Wall -g и LDFLAGS = -std = C++ 11 -lpthread -lrt к LDFLAGS = -lpthread -lrt и $ (LDFLAGS) $ (CC) $ (LDFLAGS) $ (объекты) -o $ @ до $ (CC) $ (ОБЪЕКТЫ) -o $ @ $ (LDFLAGS) это работает – Angelos

Смежные вопросы