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 ..
Related
When I link the .ld file using gcc I got the following error
/usr/bin/ld: cannot find -lreadline
collect2: error: ld returned 1 exit status
my run.sh scripts contains the following command
rm *.o *.bin *.iso
rm -rf isodir
assemble boot.s file
as --32 boot.s -o boot.o
linking the kernel with kernel.o and boot.o files
gcc -m32 -lunistd -Wno-unused-result -c kernelCheck.c -o kernel.o -std=gnu99 -ffreestanding -flto -O2 -Wall -Wextra -L/usr/lib -fno-exceptions
gcc -m32 -T linker.ld -o MoraWing.bin -ffreestanding -Wl,--build-id=none -O2 -nostdlib boot.o kernel.o -lgcc
grub-file --is-x86-multiboot MoraWing.bin
building the iso file
mkdir -p isodir/boot/grub
cp MoraWing.bin isodir/boot/MoraWing.bin
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o MoraWing.iso ./isodir
run it in qemu
qemu-system-x86_64 -cdrom MoraWing.iso
You need to install libreadline-dev, or a similar package suitable for your system (you should also specify what your system is).
I want to use the gprof profiling option in order to speed up my code. I am compiling with gcc. The problem is that there is not output file created 'gmon.out' or so. Here is a sample of the Makefile I am using:
CC = gcc
LD = gcc
#LIBGSL = -L/usr/local/lib -lgsl -lgslcblas
#LIBGSL = -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm
#LIBGSL = -L/home/dupont/gsl/gsl-2.4/lib -lgsl -lgslcblas -lm
LIBGSL = -L/n1/soft/64bit/lib -lgsl -lgslcblas -lm
CFLAGSRELEASE = -g -fopenmp -O -Wall -c -pg -I/n1/hhsoft/64bit/include
LFLAGSRELEASE = -g -pg -lm -Wl,--rpath -Wl,/usr/local/lib $(LIBGSL)
CFLAGSDEBUG = -g -p -pg -Wall
LFLAGSDEBUG = -lm
CFLAGSDEBUG = -g -p -pg -Wall -W # -DDEBUG_OUTPUT
LFLAGSDEBUG = -lm -p -pg -Wl,--rpath -Wl,/usr/local/lib $(LIBGSL)
LIBS= -L/home/dupont/folder/soft/pgplot -lm -lcpgplot /home/dupont/folder/soft/pgplot/libpgplot.a -L/usr/X11R6/lib -lX11
CFLAGS = $(CFLAGSRELEASE)
LFLAGS = $(LFLAGSRELEASE)
I don't know much about makefile, do you have any idea of what the problem could be...?
https://sourceware.org/binutils/docs-2.31/gprof/Executing.html
Your program will write the profile data into a file called gmon.out just before exiting
So there's nothing wrong if make produces your program but not gmon.out.
(anyway, you should remove -p, and ensure you use -pg both for compilation and link).
When I try to compile a code for VAR SOM AM33 using QTCreator I get this error:
c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../buscaTexto -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5 -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtWidgets -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtGui -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtCore -I. -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o main.o ../buscaTexto/main.cpp
make: c: Command not found
QTCreator's qmake generates a Makefile including this:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../buscaTexto/main.cpp
And $(CXX) is defined as following:
CXX = $(OE_QMAKE_CXX)
I know this is wrong because when I compile this code for PC I haven't any error and the Makefile define CXX as following:
CXX = g++
So It runs:
g++ c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../buscaTexto -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5 -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtWidgets -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtGui -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtCore -I. -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o main.o ../buscaTexto/main.cpp
The value of OE_QMAKE_CXX is defined in the file /opt/qt5devtools/sysroots/i686-arago-linux/environment-setup.d/qt5.sh as following:
export OE_QMAKE_CXX=$CXX
Makefile's header includes this:
# Command: /opt/qt5devtools/sysroots/i686-arago-linux/usr/bin/qt5/qmake -spec linux-oe-g++ CONFIG+=debug -o Makefile ../buscaTexto/buscaTexto.pro
the file /opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++/qmake.conf defines:
QMAKE_CXX = $(OE_QMAKE_CXX)
but the file /opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-arm-gnueabi-g++/qmake.conf defines:
QMAKE_CXX = arm-linux-gnueabi-g++
I don't know why QtCreator uses linux-oe-g++ because I have configured all for using linux-arm-gnueabi-g++.
Can someone help me?
Thank you.
I've solved this issue. The solution is here:
http://wiki.wandboard.org/index.php/Setup_QT_creator_for_developing_QT_apps_on_wandboard
What is the correct command to compile this code?
http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp
I had installed boost library in /usr/include/boost
E.g.
clang++ -std=c++03 -Wall -pedantic -g -O2 async_client.cpp -o async_client -lboost_system -lboost_thread -lpthread
Assuming your system's packaged version of Boost (or pre-configured include & lib paths). To make use of your custom built Boost library tree in ~/custom/boost:
clang++ -std=c++03 -Wall -pedantic -g -O2 \
-isystem ~/custom/boost/ ~/custom/boost/libs/asio/example/cpp03/http/client/ \
async_client.cpp -o async_client \
-L ~/custom/boost/stage/lib/ -Wl,-rpath,/home/sehe/custom/boost/stage/lib \
-lboost_system -lboost_thread -lpthread
Replace clang++ by g++ at will.
-std=c++03 -Wall -pedantic -g -O2 only for expositional purposes.
I have a C project that won't link correctly, and I suspect it's because of the --as-needed flag passed to the ld program by gcc. Because of that flag, gcc sees any linked library listed as an option before the *.c files as unnecessary, and won't link them.
PREFIX?=/usr/local
CFLAGS=-D_LARGEFILE64_SOURCE=1 -g -Wall -I${PREFIX}/apr/include/apr-1 -I${PREFIX}/apr/include/apr-util-1
LDFLAGS=-lapr-1 -pthread -laprutil-1
all: devpkg
devpkg: bstrlib.o db.o shell.o commands.o
install: all
install -d $(DESTDIR)/$(PREFIX)/bin/
install devpkg $(DESTDIR)/$(PREFIX)/bin/
clean:
rm -f *.o
rm -f devpkg
rm -rf *.dSYM
When I run this makefile I get the following.
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-util-1 -c -o bstrlib.o bstrlib.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-util-1 -c -o db.o db.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-util-1 -c -o shell.o shell.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-util-1 -c -o commands.o commands.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-util-1 -lapr-1 -pthread -laprutil-1 devpkg.c bstrlib.o db.o shell.o commands.o -o devpkg
/tmp/ccZcAm9b.o: In function `main':
/home/zach/Desktop/devpkgzed/devpkg.c:14: undefined reference to `apr_pool_initialize'
/home/zach/Desktop/devpkgzed/devpkg.c:15: undefined reference to `apr_pool_create_ex'
/home/zach/Desktop/devpkgzed/devpkg.c:29: undefined reference to `apr_getopt_init'
/home/zach/Desktop/devpkgzed/devpkg.c:31: undefined reference to `apr_getopt'
My issue is that I don't really understand how make is coming up with these commands via the CFLAGS that are set. How can I get the linker options to follow the compilation part instead of the other way around, which is triggering this issue?
Make has built-in rules to compile source files and link executables and libraries. The commands you list are produced by these rules.
The reason this fails for you is that, when linking, libraries should be listed after object files, because the linker does a single pass through its arguments and will discard any symbols that are not unresolved at the time they are seen. To correct it, put your libraries in the LDLIBS variable, not the LDFLAGS variable (i.e. just replace LDFLAGS by LDLIBS). The LDFLAGS variable is meant for non-library options for the linker, such as -L or -shared etc