I'm working on Ubuntu 12.10 with gcc version 4.7.2.
I'm trying to make the following makefile:
CC = g++
CCFLAGS = -fPIC -O3 -Wall -ffast-math -msse -msse2 -fopenmp
LINKFLAGS = -shared -Wl -fopenmp -lgomp
INPUT = im2col.cpp fastpool.cpp local_response_normalization.cpp neuron.cpp
TARGET = libcpputil.so
# If we are going to use MKL, we include additional flags
MKL_FLAGS = -D DECAF_USE_MKL
MKL_LINK_FLAGS = -lmkl_rt
all: $(INPUT)
$(CC) -c $(CCFLAGS) $(INPUT)
$(CC) $(LINKFLAGS) -o $(TARGET) *.o
all_mkl: $(INPUT)
$(CC) -c $(CCFLAGS) $(MKL_FLAGS) $(INPUT)
$(CC) $(LINKFLAGS) $(MKL_LINK_FLAGS) -o $(TARGET) *.o
speedtest_lrn: speedtest_lrn.cpp local_response_normalization.cpp
$(CC) $(CCFLAGS) -lgomp -o speedtest_lrn speedtest_lrn.cpp local_response_normalization.cpp
clean:
rm *.so
rm *.o
But somehow g++ doesn't recognize the option -wl. Here's the error that I'm getting:
make -C layers/cpp/
make[1]: Entering directory `/home/ubuntu/decaf-release-master/decaf/layers/cpp'
g++ -c -fPIC -O3 -Wall -ffast-math -msse -msse2 -fopenmp im2col.cpp fastpool.cpp local_response_normalization.cpp neuron.cpp
g++ -shared -Wl -fopenmp -lgomp -o libcpputil.so *.o
g++: error: unrecognized command line option ‘-Wl’
make[1]: *** [all] Error 1
make[1]: Leaving directory `/home/ubuntu/decaf-release-master/decaf/layers/cpp'
make: *** [all] Error 2
Failed to build the C libraries; exiting
EDIT: When I try to remove the "-wl" I get:
ubuntu#ubuntu-VirtualBox:~/decaf-release-master$ python setup.py
make -C layers/cpp/
make[1]: Entering directory `/home/ubuntu/decaf-release-master/decaf/layers/cpp'
g++ -c -fPIC -O3 -Wall -ffast-math -msse -msse2 -fopenmp im2col.cpp fastpool.cpp local_response_normalization.cpp neuron.cpp
g++ -shared -fopenmp -lgomp -o libcpputil.so *.o
make[1]: Leaving directory `/home/ubuntu/decaf-release-master/decaf/layers/cpp'
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: no commands supplied
It somehow worked when I tried it on Ubuntu 12.04 and gcc 4.7.7.
Can someone please explain what's the problem and how can I fix it?
Thanks,
Gil.
From the manual:
-Wl,option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this
syntax to pass an argument to the option. For example,
-Wl,-Map,output.map passes -Map output.map to the linker. When using the GNU linker, you can also get the same effect with
-Wl,-Map=output.map.
so, you miss the options for -Wl.
Related
NOTE PLEASE: I read the question and their answers but still, I haven't found any answer to my problem so I had to ask this question.
I have a macOS and kali Linux laptop and when I compaile this same code in my iMac the code work fine (I have some errors in exeption but I'm trying to fix them).
but when I tried to compaile the same code in my kali linux I got the following error:
└─$ make 1 ⨯
g++ -Wall -Wextra -Werror -I. -c -o main.o main.cpp
g++ -Wall -Wextra -Werror -I. -c -o Bureaucrat.o Bureaucrat.cpp
clang++ -Wall -Wextra -Werror -I. -o Bureaucrat main.o Bureaucrat.o -I Bureaucrat.hpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:27: Bureaucrat] Error 1
my makefile:
SRCS = main.cpp \
Bureaucrat.cpp \
OBJS = $(SRCS:.cpp=.o)
CPP = clang++
RM = rm -f
CPPFLAGS = -Wall -Wextra -Werror -I.
NAME = Bureaucrat
all: $(NAME)
$(NAME): $(OBJS) Bureaucrat.hpp
$(CPP) $(CPPFLAGS) -o $(NAME) $(OBJS) -I Bureaucrat.hpp
clean:
$(RM) $(OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean $(NAME)
.PHONY: all clean fclean re
I'm trying to build a python wrapper using the following Makefile:
CC=/usr/local/opt/llvm/bin/clang
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
LAPACKLDFLAGS=/usr/lib64/atlas/libsatlas.so # single-threaded blas
#LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so # multi-threaded blas
#BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
endif
ifeq ($(OS_NAME),Darwin) # Mac OS X
LAPACKLDFLAGS=-framework Accelerate # for OS X
endif
LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++ /home/lear/douze/tmp/jpeg-6b/libjpeg.a /usr/lib64/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp
CPYTHONFLAGS=-I/usr/include/python2.7
SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
OBJ := $(SOURCES:%.cpp=%.o)
HEADERS := $(shell find . -name '*.h')
all: deepmatching
.cpp.o: %.cpp %.h
$(CC) -o $# $(CFLAGS) -c $+
deepmatching: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(LDFLAGS) $(LAPACKLDFLAGS)
deepmatching-static: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(STATICLAPACKLDFLAGS)
python: $(HEADERS) $(OBJ)
# swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
/usr/local/opt/llvm/bin/clang $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
/usr/local/opt/llvm/bin/clang -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)
clean:
rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???
Previously, CC was set to g++, however, when I tried to build it like this, I'd get "ERROR: clang: error: unsupported option '-fopenmp".
Now I installed "brew install llvm" as this comes with the -fopenmp option. The unsupported error is resolved for now, but now the compiler doesn't seem to find a header file:
(base) MacBook-Pro-van-Brent:deepmatching BrentDeHauwere$ make python
/usr/local/opt/llvm/bin/clang -o hog.o -fPIC -Wall -g -std=c++11 -Dinteger=int -fopenmp -DUSE_OPENMP -O3 -I/usr/local/opt/llvm/include -c hog.cpp
In file included from hog.cpp:18:
In file included from ./std.h:20:
/usr/local/opt/llvm/bin/../include/c++/v1/math.h:300:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [hog.o] Error 1
I've tried setting options (I might have set them incorrectly) like -L/usr/local/opt/llvm/lib and -I/usr/local/opt/llvm/include, but no result so far. Any idea how I could point the compiler to the right direction for the header files?
Try running xcode-select —install in your terminal. This installs the xcode command line tools which should also install system headers files (as part of the macos sdk) and set your system include paths.
After try to use this attached makefile the error that appears is :
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [Ass1F] Error 1
the makefile is :
all: Ass1F
Ass1F: bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
g++ -o bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
#echo 'Finished building target: Ass1F'
#echo ' '
bin/x.o: src/x.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/x.o src/x.cpp
bin/y.o: src/y.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/y.o src/y.cpp
bin/z.o: src/z.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/z.o src/z.cpp
bin/w.o: src/w.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/w.o src/w.cpp
bin/main.o: src/main.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/main.o src/main.cpp
clean:
rm -f bin/*
what should I do with this problem?
the reason is the makefile or something in the code?
just to let you know we used eclipse to write the code and everything work perfectly- no any bugs.
thanks
Line g++ -o bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o tries to create executable named bin/main.o, overwriting its previous contents.
It should be e.g. g++ -o Ass1F bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
Your makefile recipe for Ass1F is incorrect, it doesn't specify the output file, os make uses bin/main.o as the output file instead of one of the input files.
You can simplify the makefile by using pattern rules (i.e. with wildcards) and using pre-defined variables such as $# (the name of the target) and $^ (the list of prerequisites) and CXX (the C++ compiler):
CXXFLAGS = -g -Wall -Weffc++
CPPFLAGS =
LDFLAGS =
LDLIBS =
all: Ass1F
Ass1F: bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
$(CXX) $(LDFLAGS) -o $# $^ $(LDLIBS)
#echo 'Finished building target: Ass1F'
#echo ' '
bin/%.o: src/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $# $^
clean:
rm -f bin/*
sorry about my bad english...
Well, I'm now to linux, perl and c++, but I have to do some codes for the university and I'm getting some troubles while doing the makefile.
I have a code in perl which is running perfectly. As well, I have a code in C++ that calls perl as a subroutine. Everything is working properly, but when I do the makefile on my computer, it says:
sathlervbn Spam C # make clean; make
rm -f *.o
g++ -Wall -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.14/CORE -c -o main.o main.cpp
g++ -L/usr/lib -Wall -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.14/CORE - lperl -ldl -lm -lpthread -lc -lcrypt -o main libSpam.a main.o
/usr/bin/ld: cannot find -lperl
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
The problem is that when I run the makefile in my professor's computer, it's works...
Here is the code of makefile:
#CC= /usr/bin/g++
CPP = g++
CPPFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ccopts)
#LD= /usr/bin/g++
LD = g++
#LFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ldopts)
LFLAGS = -Wall -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.14/CORE - lperl -ldl -lm -lpthread -lc -lcrypt
MAINOBJS = libSpam.a main.o
EMAILS = main
EXECS = $(EMAILS)
#Regra Implicita:
.c.o:
$(CPP) $(CPPFLAGS) -c $<
all: emails
emails: $(EMAILS)
main: $(MAINOBJS)
$(LD) -L/usr/lib $(LFLAGS) -o $# $(MAINOBJS)
clean:
rm -f *.o
Does anyone know how to solve it?
You need to install the perl library for C. If you're on a Debian based system (including Ubuntu) sudo apt-get install libperl-dev or something similar may be sufficient, depending on which version of perl you're using.
Update: ok, this is a bit strange - I've installed perl-base, and it installed /usr/lib/libperl.so.5.14 but it did not make a /usr/lib/libperl.so symlink as you'd expect. I wonder why not? If I manually create the symlink with ln -s /usr/lib/libperl.so.5.14 /usr/lib/libperl.so it links correctly.
Update the second I had perl-base installed, but not libperl-dev which gave me /usr/lib/libperl.so.5.14 but not /usr/lib/libperl.so. I suspect (don't know for sure, but strongly suspect) that the correct answer isn't to manually make the symlink, but to install libperl-dev.
So I have this makefile and I want the target all just to invoke the target expertest, but apparently the way I'm doing it is wrong because i'm getting the error
"make: exprtest: Command not found
make: * [all] Error 127
"
this is the makefile:
all:
exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
driver.o: driver.cpp scanner.hpp driver.hpp
g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
bison parser.ypp
g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
flex -t scanner.ll > scanner.cpp
g++ -Wall -g -c scanner.cpp
clean:
rm parser.tab.hpp parser.tab.cpp scanner.cpp
And you can always have make call a new instance of make.
For example:
all:
$(MAKE) exprtest
exprtest:
do exprtest stuff
Typing make all will indirectly do make exprtest.
Put exprtest on the same line as all. Dependencies come after the colon, commands come on the following lines, indented.
target: dependencies
[tab] system command
So in your case it all becomes:
all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
You want to do something like
all: exprtest
What that says is "all depends on exprtest to be successful".