I can't compile my project.
When I run make command I get the following error.
If I try compile shareMemoryWriter.cpp alone with command
g++ -std=c++11 shareMemoryWriter.cpp main2.cpp -o main -lpthread -lrt
the compile succeed
operating system: 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 $#
.cpp.o:
$(CC) $(CFLAGS) -c $< -o $#
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $^
Make compile output:
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
Don't do this:
CFLAGS=-Wall -g -std=c++11 -lpthread -lrt
Linker flags do not belong on your compile line, only on link line.
Don't do this either:
LDFLAGS= -std=c++11 -lpthread -lrt
The -std=c++11 is a compile flag, and doesn't belong on your link line.
This:
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
puts libraries at the beginning of the link line. They should be at the end. This answer explains why that's important.
Related
Please I need help, I need to install this library quickly for a project I am working on (https://github.com/LuaDist/mapm) and I don't understand makefile. Per the instructions I run the command "make" and get the following output:
gcc -c -Wall -O2 mapmhsin.c
gcc -c -Wall -O2 mapm_pow.c
gcc -c -Wall -O2 mapm_log.c
gcc -c -Wall -O2 mapm_lg2.c
gcc -c -Wall -O2 mapm_lg4.c
gcc -c -Wall -O2 mapm_exp.c
gcc -c -Wall -O2 mapm_lg3.c
gcc -c -Wall -O2 mapmasin.c
gcc -c -Wall -O2 mapmasn0.c
gcc -c -Wall -O2 mapm_sin.c
gcc -c -Wall -O2 mapm5sin.c
gcc -c -Wall -O2 mapmrsin.c
gcc -c -Wall -O2 mapm_cpi.c
gcc -c -Wall -O2 mapmsqrt.c
gcc -c -Wall -O2 mapmcbrt.c
gcc -c -Wall -O2 mapmgues.c
gcc -c -Wall -O2 mapmfact.c
gcc -c -Wall -O2 mapm_gcd.c
gcc -c -Wall -O2 mapmipwr.c
gcc -c -Wall -O2 mapmpwr2.c
gcc -c -Wall -O2 mapm_rnd.c
gcc -c -Wall -O2 mapm_flr.c
gcc -c -Wall -O2 mapm_fpf.c
gcc -c -Wall -O2 mapm_rcp.c
gcc -c -Wall -O2 mapmstck.c
gcc -c -Wall -O2 mapm_div.c
gcc -c -Wall -O2 mapm_mul.c
gcc -c -Wall -O3 mapmfmul.c
gcc -c -Wall -O2 mapm_fft.c
gcc -c -Wall -O2 mapm_add.c
gcc -c -Wall -O2 mapmistr.c
gcc -c -Wall -O2 mapm_set.c
gcc -c -Wall -O2 mapm_fam.c
gcc -c -Wall -O3 mapmutil.c
gcc -c -Wall -O2 mapmutl2.c
gcc -c -Wall -O2 mapmutl1.c
gcc -c -Wall -O2 mapmcnst.c
rm -f libmapm.a
ar rc libmapm.a mapmhasn.o mapmhsin.o mapm_pow.o mapm_log.o mapm_lg2.o mapm_lg4.o mapm_exp.o mapm_lg3.o mapmasin.o mapmasn0.o mapm_sin.o mapm5sin.o mapmrsin.o mapm_cpi.o mapmsqrt.o mapmcbrt.o mapmgues.o mapmfact.o mapm_gcd.o mapmipwr.o mapmpwr2.o mapm_rnd.o mapm_flr.o mapm_fpf.o mapm_rcp.o mapmstck.o mapm_div.o mapm_mul.o mapmfmul.o mapm_fft.o mapm_add.o mapmistr.o mapm_set.o mapm_fam.o mapmutil.o mapmutl2.o mapmutl1.o mapmcnst.o
gcc -c -Wall -O2 calc.c
gcc -s -static -o calc calc.o libmapm.a -lm
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [Makefile:63: calc] Error 1
It looks like everything goes fine until the end:
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
Is there any way I fix this, and what does the command -lm and -lc do?
I've done this Makefile with the following structure:
BIN_FILES = array cliente servidor
CC = gcc
CCGLAGS = -Wall -g
all: CFLAGS=$(CCGLAGS)
all: $(BIN_FILES)
.PHONY : all
array.o: array.c array.h
$(CC) -c -Wall -fPIC array.c
cliente.o: cliente.c array.h
$(CC) -Wall -c cliente.c
cliente: cliente.o array.h
$(CC) -Wall -o cliente -ldl -lrt
servidor.o: servidor.c mensajes.h
$(CC) -Wall -c servidor.c -lrt -lpthread
servidor: servidor.o
$(CC) -o $# servidor -lrt -lpthread
clean:
rm -f $(BIN_FILES) *.o
.SUFFIXES:
.PHONY : clean
But when I try to execute it, it only works the first rule. Then the execution stops. My final objective is to make each rule work, because if I execute each rule separately it works:
gcc -c -Wall -fPIC array.c
gcc -fPIC -shared -o libarray.so array.o -lrt
gcc -Wall -o cliente cliente.c -ldl -lrt
gcc -Wall -o servidor servidor.c -lrt -lpthread
Thanks
Edit:
Now I obtain the following error applying #Jens modifications:
make: *** No rule to make the objective 'array', necesary for 'all'. Stop.
The targets for cliente.o and servidor.o should use -c instead of -o, i.e. you want to compile to object files.
There's also no point in specifying header files as dependencies in targets cliente and servidor. The commands for these only link, but don't compile files.
servidor: servidor.o
$(CC) -o $# servidor.o -lrt -lpthread
There's also no point is specifying library options -ldl etc when compiling to object files with -c.
cliente.o: cliente.c array.h
$(CC) -Wall -c cliente.c
This question already has answers here:
GNU make yields "commands commence before first target" error
(4 answers)
Closed 7 years ago.
I have been trying to compile GLEW with MINGW on Windows as explained here
However I get the "commands commence before first target"
Makefile (I cannot get the formatting to work here)
Thanks
Make expect “rules” with the following shape:
target: prerequisites ...
command
...
You need to define a target in your makefile before the first call to gcc. Just add a line with glew: in the beginning. Each line with a command need to start with a tab character.
Have a look at the introduction section of the make manual for more information: https://www.gnu.org/software/make/manual/html_node/Introduction.html
modified version of your makefile (makefile.mod)
## makefile based on answer http://stackoverflow.com/a/6005262/663518
## http://stackoverflow.com/questions/6005076/building-glew-on-windows-with-mingw
.PHONY: glew
glew: libs exe
## libs
libs: lib/glew32.dll lib/glew32mx.dll
lib/glew32.dll:
#echo ##compiling libglew32
gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32.a src/glew.o
lib/glew32mx.dll:
#echo ##compiling libglew32mx
gcc -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32mx.a src/glew.mx.o
## glewinfo and visualinfo programs.
exe: bin/glewinfo.exe bin/visualinfo.exe
bin/glewinfo.exe: lib/glew32.dll
#echo ##compiling glewinfo.exe
gcc -c -O2 -Wall -W -Iinclude -o src/glewinfo.o src/glewinfo.c
gcc -O2 -Wall -W -Iinclude -o bin/glewinfo.exe src/glewinfo.o -Llib -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
bin/visualinfo.exe: lib/glew32.dll
#echo ##compiling visualinfo
gcc -c -O2 -Wall -W -Iinclude -o src/visualinfo.o src/visualinfo.c
gcc -O2 -Wall -W -Iinclude -o bin/visualinfo.exe src/visualinfo.o -Llib -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
> make -f makefile.mod
##compiling libglew32
gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude...
...
make -f makefile.mod libs builds the dll
make -f makefile.mod exe builds the exe and dll (if necessary)
Last time i asked sth about how to use CLAPACK.
Using CLAPACK undefined reference error
After that i tried to separate everything for a larger project.
Now I have "blitzLA.cpp" "InterfaceCLAPACK.cpp" "InterfaceCLAPACK.hpp"
I could successfully make it work just by calling
g++ -Wall -g InterfaceCLAPACK.cpp blitzLA.cpp -llapack -lblas -lf2c -o blitzLA
But if I do the Makefile, it gives me some errors.. My makefile is shown below.
CC = g++
CFLAGS = -Wall -g
linker = -llapack -lblas -lf2c
blitzLA: blitzLA.o InterfaceCLAPACK.o
${CC} ${CFLAGS} InterfaceCLAPACK.o blitzLA.o -o blitzLA
blitzLA.o: blitzLA.cpp InterfaceCLAPACK.hpp
${CC} ${CFLAGS} ${linker} -c blitzLA.cpp
InterfaceCLAPACK.o: InterfaceCLAPACK.cpp InterfaceCLAPACK.hpp
${CC} ${CFLAGS} ${linker} -c InterfaceCLAPACK.cpp
clean:
rm -rf *.o blitzLA
I guess the problem is where do i leave "-llapack -lblas -lf2c"..Now i get the errors shown below.
g++ -Wall -g -llapack -lblas -lf2c -c blitzLA.cpp
g++ -Wall -g -llapack -lblas -lf2c -c InterfaceCLAPACK.cpp
g++ -Wall -g InterfaceCLAPACK.o blitzLA.o -o blitzLA
InterfaceCLAPACK.o: In function `quantfin::interfaceCLAPACK::SolveLinear(blitz::Array<double, 2>
bunch of things here..
/home/baozi/Dropbox/Linux/LinearAlgebra/InterfaceCLAPACK.cpp:64: undefined reference to `dgttrf_'
/home/baozi/Dropbox/Linux/LinearAlgebra/InterfaceCLAPACK.cpp:67: undefined reference to `dgttrs_'
collect2: error: ld returned 1 exit status
make: *** [blitzLA] Error 1
Where do i go wrong.. Help plz
I am using the Boost library in Unix, GCC. I read the following topic: Boost static linking and added -static to my Makefile. However, this does not work.
Here is my Makefile:
all: nbbo
nbbo: nbbo.o reader.o
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -L/usr/lib -lboost_filesystem -lboost_serialization -lboost_iostreams -lz -I /usr/include/boost -o nbbo nbbo.o reader.o
nbbo.o: nbbo.cpp
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -I /usr/include/boost -c -o nbbo.o nbbo.cpp
reader.o: reader.cc reader.h
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -I /usr/include/boost -c -o reader.o reader.cc
clean:
rm *.o
And here is the error message:
nbbo.o: In function `__tcf_10':
nbbo.cpp:(.text+0x3d9): undefined reference to `boost::serialization::extended_type_info::key_unregister() const'
nbbo.cpp:(.text+0x3e3): undefined reference to `boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister()'
nbbo.cpp:(.text+0x3fb): undefined reference to `boost::serialization::typeid_system::extended_type_info_typeid_0::~extended_type_info_typeid_0()'
etc
Which "UNIX" are you using? Using the -static flag should work fine on linux. But not on OSX. On OSX you have to remove the static flag and give the complete path to the library in order to link statically. I dont know how this would work on other "UNIXes"
eg.
g++ ..... /path/to/your/lib.a ... -o ..